dpnp.nonzero
- dpnp.nonzero(x1)[source]
Return the indices of the elements that are non-zero.
For full documentation refer to
numpy.nonzero.Limitations
Input array is supported as
dpnp.ndarray. Otherwise the function will be executed sequentially on CPU. Input array data types are limited by supported DPNP Data types.See also
dpnp.flatnonzeroReturn indices that are non-zero in the flattened version of the input array.
dpnp.count_nonzeroCounts the number of non-zero elements in the input array.
Notes
While the nonzero values can be obtained with
a[nonzero(a)], it is recommended to usex[x.astype(bool)]orx[x != 0]instead, which will correctly handle 0-d arrays.Examples
>>> import dpnp as np >>> x = np.array([[3, 0, 0], [0, 4, 0], [5, 6, 0]]) >>> out = np.nonzero(x) >>> for arr in out: >>> [i for i in arr] [0, 1, 2, 2] [0, 1, 0, 1]
>>> x2 = np.array([3, 0, 0, 0, 4, 0, 5, 6, 0]) >>> out2 = np.nonzero(x2) >>> for arr in out2: >>> [i for i in arr] [0, 4, 6, 7]