mindspore.ops.nonzero
- mindspore.ops.nonzero(x)[source]
Return a Tensor of the positions of all non-zero values.
- Parameters
x (Tensor) – The shape of Tensor is \((x_1, x_2, ..., x_R)\). The data type is Number or Bool.
- Returns
Tensor, a 2-D Tensor whose data type is int64, containing the positions of all non-zero values of the input.
- Raises
TypeError – If x is not Tensor.
ValueError – If ‘x’ dim equal to 0.
- Supported Platforms:
GPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor >>> import mindspore.ops as ops >>> x = Tensor(np.array([[[1, 0], [-5, 0]]]), mindspore.int32) >>> output = ops.nonzero(x) >>> print(output) [[0 0 0] [0 1 0]]