You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
In [1]: importnumpyasnpIn [2]: ar=np.arange(10)
In [3]: np.count_nonzero(ar).__class__Out[3]: intIn [4]: np.count_nonzero(ar, axis=0).__class__Out[4]: numpy.int64# i.e. np.intp
The text was updated successfully, but these errors were encountered:
BvB93
changed the title
BUG: count_nonzero can return either a builtin int or numpy's intpcount_nonzero can return either a builtin int or numpy's intpSep 30, 2021
The return type of
np.count_nonzero()
is currently somewhat inconsistent:axis is None and not keepdims
.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 aroundnp.ndarray.sum()
with its dtype explicitly set tonp.intp
:numpy/numpy/core/numeric.py
Lines 484 to 495 in 4ccfbe6
Reproducing code example:
MacOS 10.15.6; Python 3.8.5; NumPy 1.20.0.dev0+eb2c751
The text was updated successfully, but these errors were encountered: