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 structuresarrays andlists
Arrays: are used to storehomogeneous data (same data type) offixed size storing insequential order in memory
Lists are used to store data ofgrowing in size and storing this data in available placeanywhere(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:
- Able to store different data types in the same list
- Storing each item in random location in the memory
- Good for the scenario where list can grow dynamically
- Inbuilt data type.
- It has more inbuilt functions
- Appending will take less time in O(1) time
NumPy Array:
- Can store only one data type in an array at any time
- Storing each item is sequential which makes array more effective in processing.
- Good for the scenario where the items are fixed size and same data time
- Need to install external library NumPy
- No extra functions, so it will not more memory store.
- Appending elements will take more time in O(N) time
Happy Learning!!!
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse