[Numpy-discussion] Improving performance of the `numpy.any` function.

dan_patterson dan_patterson at outlook.com
Wed Apr 14 21:53:58 EDT 2021


a = np.zeros(1_000_000)

a[100] = 1

%timeit np.any(a)
814 µs ± 17.8 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

%timeit np.any(a == 1)
488 µs ± 5.68 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

Haven't investigated further since your times are much longer than mine and
secondly the equality check for 1 implies that perhaps a short circuit
actually exists somewhere 



--
Sent from: http://numpy-discussion.10968.n7.nabble.com/


More information about the NumPy-Discussion mailing list