nonzero

nonzero(x: array, /) Tuple[array, ...]

Returns the indices of the array elements which are non-zero.

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 of x and each of size n (where n 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.