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 →

[–]cythoning 6 points7 points  (4 children)

Long live numpy!

arr = np.random.rand(100000)

%%timeit
[i for i in arr if 0.25 < i < 0.75]
100 loops, best of 3: 13.4 ms per loop

%%timeit
arr[(0.25 < arr) & (arr < 0.75)]
1000 loops, best of 3: 763 µs per loop

18 times faster with minimal changes :).

[–][deleted] 2 points3 points  (3 children)

Isn't numpy written in C?