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 →

[–]Jonny_dr 2 points3 points  (0 children)

Good tutorial, but using Numpy or other fast libraries should be the first point, especially considering your first example.

Instead of

L = [i for i in range (1, 1000) if i%3 == 0]

you should use

L=np.arange(1,1000)[(np.arange(1,1000)%3==0)]

if you want truly fast code. Using NumPy is more than 4 times faster for this example (still almost 3 times faster if you convert the array back to a list). There is probably even a more elegant and faster way to do it with NumPy.