DEV Community

chanduthedev
chanduthedev

Posted on • Updated on

Python List vs NumPy Array

I will try to explain why NumPy is more powerful and efficient compare with Python List.

First we will see basic definition of the list vs Array programming terminology

Lets see basic data structures arrays and lists

Arrays: are used to store homogeneous data (same data type) of fixed size storing in sequential order in memory
Lists are used to store data of growing in size and storing this data in available place anywhere(not sequential) in the memory.

Almost same logic applies to Python List and NumPy Array. You can see in the below picture, how list and array stores data in memory.

Python list and NumPy array

Python List:

  1. Able to store different data types in the same list
  2. Storing each item in random location in the memory
  3. Good for the scenario where list can grow dynamically
  4. Inbuilt data type.
  5. It has more inbuilt functions
  6. Appending will take less time in O(1) time

NumPy Array:

  1. Can store only one data type in an array at any time
  2. Storing each item is sequential which makes array more effective in processing.
  3. Good for the scenario where the items are fixed size and same data time
  4. Need to install external library NumPy
  5. No extra functions, so it will not more memory store.
  6. Appending elements will take more time in O(N) time

Happy Learning!!!

Top comments (0)