Open
Description
The return type of np.count_nonzero()
is currently somewhat inconsistent:
- A builtin integer is returned if
axis is None and not keepdims
. - An
np.intp
(or an array) is returned otherwise.
The former case is handled by the an identically named function in the np.core._multiarray_umath
module (which apparently always returns an int
) while the latter is effectively a wrapper around
np.ndarray.sum()
with its dtype explicitly set to np.intp
:
Lines 484 to 495 in 4ccfbe6
Reproducing code example:
MacOS 10.15.6; Python 3.8.5; NumPy 1.20.0.dev0+eb2c751
In [1]: import numpy as np
In [2]: ar = np.arange(10)
In [3]: np.count_nonzero(ar).__class__
Out[3]: int
In [4]: np.count_nonzero(ar, axis=0).__class__
Out[4]: numpy.int64 # i.e. np.intp