Closed zhaok12 closed 6 years ago
I remember numpy.take()
is faster than fancy index.
In [3]: import numpy as np
...: import random
...:
...: arr = np.random.randn(10000, 5)
...: indexer = np.arange(10000)
...: random.shuffle(indexer)
...:
In [4]: timeit arr[indexer]
1000 loops, best of 3: 241 µs per loop
In [5]: timeit arr.take(indexer, axis=0)
10000 loops, best of 3: 96.2 µs per loop
In [6]: timeit np.take(arr, indexer, axis=0)
10000 loops, best of 3: 101 µs per loop
Reference: http://wesmckinney.com/blog/numpy-indexing-peculiarities/
close this now
why using numpy.take() rather than “fancy” indexing (indexing arrays using arrays) , for example in pmf.py, while the “fancy” indexing is much faster.