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

Brock Mendel jbrockmendel at gmail.com
Wed Apr 14 22:34:04 EDT 2021


FWIW in https://github.com/pandas-dev/pandas/issues/32339 I tried
short-circuiting (left == right).all() with a naive cython implementation.
In the cases that _dont_ short-circuit, it was 2x slower than
np.array_equal.

On Wed, Apr 14, 2021 at 6:54 PM dan_patterson <dan_patterson at outlook.com>
wrote:

> 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/
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210414/8fbc66a7/attachment.html>


More information about the NumPy-Discussion mailing list