mindspore.ops.NonZero

class mindspore.ops.NonZero[source]

Return a Tensor of the positions of all non-zero values.

Inputs:
  • input (Tensor) - The input Tensor, its rank should be greater than or eaqual to 1.

Outputs:

Tensor, a 2-D Tensor whose data type is int64, containing the positions of all non-zero values of the input.

Raises
Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> input = Tensor(np.array([1, 0, 2, 0, 3]), mindspore.int32)
>>> output = ops.NonZero()(input)
>>> print(output)
[[0]
 [2]
 [4]]