import numpy as np, datetime
lrg = np.arange(2).reshape((2, -1)).repeat(1000000, -1).flatten()
t0 = datetime.datetime.now()
flt = lrg[lrg == 0]
print(datetime.datetime.now() - t0)
t0 = datetime.datetime.now()
flt = np.array([x for x in lrg if x == 0])
print(datetime.datetime.now() - t0)
Efficient thresholding filter of an array with numpy