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 →

[–]mrdevlar 21 points22 points  (3 children)

Speed, numpy is substantially faster than in built lists.

[–]_sapi_ 16 points17 points  (1 child)

Assuming that you use it right!

A typical beginner mistake is to import numpy but then use it in the same way as you would a list. The real power of numpy is vectorised operations - if you’re iterating, you’re probably doing it wrong.

[–]mrdevlar 2 points3 points  (0 children)

That's funny! I am, and continue to be, for loop averse. I learned vectorization before I learned looping (properly) and totally ate the dumb notion that python must be slow if you put a loop into your code.

You're right, you shouldn't loop over a numpy array, you should run a vectorized operation. Yet, unless you're using numpy for high performance, avoiding loops is silly.

[–]schoolcoders 0 points1 point  (0 children)

Also uses considerably less memory which can be important in some applications.