[Numpy-discussion] count_nonzero axis argument?

Juan Nunez-Iglesias jni.soma at gmail.com
Mon Sep 17 08:19:15 EDT 2018

On Mon, Sep 17, 2018, at 9:37 PM, Matthew Brett wrote:
> >>> np.better_count_nonzero([[10, 11], [0, 3]], axis=1)
> array([2, 1])
> It would be much more useful if it did...

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!


.. [1] https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.apply_along_axis.html

More information about the NumPy-Discussion mailing list