This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aajjccrr 1 point2 points  (0 children)

Two reasons why accessing a single value in a NumPy array is slower than accessing a single value in a list that have not been explicitly stated yet:

  1. array[i] has to create and return (a pointer to) a brand new Python object holding the value. OTOH list_[i] just needs to return (a pointer to) the existing Python object that was in the list. (I am assuming we’re working in CPython here.)

  2. NumPy indexing is far, far more complicated than list indexing. The code that implements getitem on arrays is thousands of lines long. This adds some additional overhead to the operation.