dask 2021.10.0

ParametersReturnsBackRef
count_nonzero(a, axis=None)

This docstring was copied from numpy.count_nonzero.

Some inconsistencies with the Dask version may exist.

The word "non-zero" is in reference to the Python 2.x built-in method __nonzero__() (renamed __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 __nonzero__() or __bool__() method evaluated to True .

Parameters

a : array_like

The array for which to count non-zeros.

axis : int or tuple, optional

Axis or tuple of axes along which to count non-zeros. Default is None, meaning that non-zeros will be counted along a flattened version of a .

versionadded
keepdims : bool, optional (Not supported in Dask)

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.

versionadded

Returns

count : int or array of int

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.

Counts the number of non-zero values in the array a .

See Also

nonzero

Return the coordinates of all the non-zero values.

Examples

This example is valid syntax, but we were not able to check execution
>>> np.count_nonzero(np.eye(4))  # doctest: +SKIP
4
This example is valid syntax, but we were not able to check execution
>>> a = np.array([[0, 1, 7, 0],  # doctest: +SKIP
...  [3, 0, 2, 19]])
... np.count_nonzero(a) # doctest: +SKIP 5
This example is valid syntax, but we were not able to check execution
>>> np.count_nonzero(a, axis=0)  # doctest: +SKIP
array([1, 1, 2, 1])
This example is valid syntax, but we were not able to check execution
>>> np.count_nonzero(a, axis=1)  # doctest: +SKIP
array([2, 3])
This example is valid syntax, but we were not able to check execution
>>> np.count_nonzero(a, axis=1, keepdims=True)  # doctest: +SKIP
array([[2],
       [3]])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

dask.array.routines.nonzero

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /dask/array/routines.py#2042
type: <class 'function'>
Commit: