- jax.numpy.count_nonzero(a, axis=None, keepdims=False)#
Counts the number of non-zero values in the array
LAX-backend implementation of
Original docstring below.
The word “non-zero” is in reference to the Python 2.x built-in method
__bool__()in Python 3.x) of Python objects that tests an object’s “truthfulness”. For example, any number is considered truthful if it is nonzero, whereas any string is considered truthful if it is not the empty string. Thus, this function (recursively) counts how many elements in
a(and in sub-arrays thereof) have their
__bool__()method evaluated to
a (array_like) – The array for which to count non-zeros.
keepdims (bool, optional) – If this is set to True, the axes that are counted are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
count – Number of non-zero values in the array along a given axis. Otherwise, the total number of non-zero values in the array is returned.
- Return type: