
Hi, Is there any reason that np.count_nonzero should not take an axis argument? As in:
np.better_count_nonzero([[10, 11], [0, 3]], axis=1) array([2, 1])
It would be much more useful if it did... Cheers, Matthew

On Mon, 2018-09-17 at 12:37 +0100, Matthew Brett wrote:
No, sounds like an obvious improvement, but as also with those, someone has to volunteer to do it... Coding it will probably mean adding the NpyIter and possibly fast paths (not sure about the state of count nonzero), but should not be very difficult. - Sebastian

On Mon, Sep 17, 2018, at 9:37 PM, Matthew Brett wrote:
You might know about this already, but I not too long ago discovered np.apply_along_axis [1], which is a magical function that makes all functions axis aware. Obviously I would support adding an axis keyword to count_nonzero, but in the meantime this function gets you there quickly! Juan. .. [1] https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.apply_alon...

On Mon, Sep 17, 2018 at 7:38 AM Matthew Brett <matthew.brett@gmail.com> wrote:
It already does (since version 1.12.0): https://docs.scipy.org/doc/numpy/reference/generated/numpy.count_nonzero.htm... Warren It would be much more useful if it did...

On Mon, 2018-09-17 at 12:37 +0100, Matthew Brett wrote:
No, sounds like an obvious improvement, but as also with those, someone has to volunteer to do it... Coding it will probably mean adding the NpyIter and possibly fast paths (not sure about the state of count nonzero), but should not be very difficult. - Sebastian

On Mon, Sep 17, 2018, at 9:37 PM, Matthew Brett wrote:
You might know about this already, but I not too long ago discovered np.apply_along_axis [1], which is a magical function that makes all functions axis aware. Obviously I would support adding an axis keyword to count_nonzero, but in the meantime this function gets you there quickly! Juan. .. [1] https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.apply_alon...

On Mon, Sep 17, 2018 at 7:38 AM Matthew Brett <matthew.brett@gmail.com> wrote:
It already does (since version 1.12.0): https://docs.scipy.org/doc/numpy/reference/generated/numpy.count_nonzero.htm... Warren It would be much more useful if it did...
participants (4)
-
Juan Nunez-Iglesias
-
Matthew Brett
-
Sebastian Berg
-
Warren Weckesser