[SciPy-Dev] np.any(), np.all()
Dieter Werthmüller
dieter at werthmuller.org
Mon Jul 2 14:03:36 EDT 2018
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
More information about the SciPy-Dev
mailing list