numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
flatnonzero(a)

This is equivalent to np.nonzero(np.ravel(a))[0].

Parameters

a : array_like

Input data.

Returns

res : ndarray

Output array, containing the indices of the elements of :None:None:`a.ravel()` that are non-zero.

Return indices that are non-zero in the flattened version of a.

See Also

nonzero

Return the indices of the non-zero elements of the input array.

ravel

Return a 1-D array containing the elements of the input array.

Examples

>>> x = np.arange(-2, 3)
... x array([-2, -1, 0, 1, 2])
>>> np.flatnonzero(x)
array([0, 1, 3, 4])

Use the indices of the non-zero elements as an index array to extract these elements:

>>> x.ravel()[np.flatnonzero(x)]
array([-2, -1,  1,  2])
See :

Back References

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

numpy.nonzero numpy.ma.core.MaskedArray.nonzero numpy.ma.core.nonzero dask.array.routines.flatnonzero

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


GitHub : /numpy/core/numeric.py#625
type: <class 'function'>
Commit: