[SciPy-Dev] np.any(), np.all()

Phillip Feldman phillip.m.feldman at gmail.com
Wed Jul 4 00:39:36 EDT 2018


Performing a test (to determine whether the loop should be aborted) after
looking at each element would cause `np.any` to run slower if all elements
are zero, or if the first non-zero element is near the end of the array.
Possibly a separate method that operates in this fashion is needed?

Phillip


On Mon, Jul 2, 2018 at 11:03 AM, Dieter Werthmüller <dieter at werthmuller.org>
wrote:

> Dear devs,
>
> Sorry for posting a numpy-issue on the scipy-list. I am not (yet)
> subscribed to the numpy list, but I believe that the two community have a
> big enough overlap so it shouldn't matter too much where I post it.
>
> I recently encountered the issue that I found that np.any(x) is sort of
> veeeery slow for big arrays, even if every element has a non-zero value and
> I only need a True/False response. So my thinking was that if np.any(x)
> encounters the first non-zero value it should simply return True, which
> should take basically no time at all if every element in the array is
> non-zero.
>
> Searching for it I found the following two old issues on numpy:
>
> 1. https://github.com/numpy/numpy/issues/2269
>
> It is an issue from 2010, but got some traffic again in 2016 and 2017.
>
>
> 2. https://github.com/numpy/numpy/issues/3446
>
> This is a related issue from 2013, reporting a potential performance
> regression between numpy 1.6.2 and 1.7.0, that got some traffic in 2016
> again as well.
>
>
> I just wanted to ask about the opinions of devs more familiar with these
> two functions (np.all(), np.any()). Would there be better ways to check if
> any element in a big (1D or higher dimensions)-array is non-zero (or the
> reverse with np.all)?
>
>
> Thanks,
> Dieter
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at python.org
> https://mail.python.org/mailman/listinfo/scipy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20180703/3615b8b9/attachment.html>


More information about the SciPy-Dev mailing list