Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

chanduthedev
chanduthedev

Posted on • Edited 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 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 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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I am a developer
  • Location
    London
  • Joined

More fromchanduthedev

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp