Give it a try. This creates an idea of ββthe same data.
Thus, the syntax will look like this:
b=a[a>threshold]
b is not a new array (as opposed to where), but is a representation of where the elements satisfy the boolean in the index.
Example:
import numpy as np import time a=np.random.random_sample(int(1e9)) t1=time.time() b=a[a>0.5] print(time.time()-t1,'seconds')
On my machine that prints 22.389815092086792 seconds
change
I tried the same with np.where and it is just as fast. I'm suspicious: are you deleting these values ββfrom the array?
user648852
source share