nonzero¶
- nonzero(x: array, /) Tuple[array, ...] ¶
Returns the indices of the array elements which are non-zero.
Note
If
x
has a complex floating-point data type, non-zero elements are those elements having at least one component (real or imaginary) which is non-zero.Note
If
x
has a boolean data type, non-zero elements are those elements which are equal toTrue
.Data-dependent output shape
The shape of the output array for this function depends on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See Data-dependent output shapes section for more details.
- Parameters:
x (array) – input array. Must have a positive rank. If
x
is zero-dimensional, the function must raise an exception.- Returns:
out (Typle[array, …]) – a tuple of
k
arrays, one for each dimension ofx
and each of sizen
(wheren
is the total number of non-zero elements), containing the indices of the non-zero elements in that dimension. The indices must be returned in row-major, C-style order. The returned array must have the default array index data type.
Notes
Changed in version 2022.12: Added complex data type support.