mindspore.ops.is_nonzero

mindspore.ops.is_nonzero(input)[source]

Determine whether the input Tensor contains 0 or False. The input can only be a single element.

Parameters

input (Tensor) – The input tensor.

Returns

Bool, returns False if the input Tensor contains a unit element of 0 or a single element of False, otherwise returns True.

Raises
  • TypeError – If input is not Tensor.

  • ValueError – If the element number of input is not equal to 1.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore import Tensor, ops
>>> x1 = Tensor([[[False]]])
>>> x2 = Tensor([[3.5]])
>>> out1 = ops.is_nonzero(x1)
>>> print(out1)
False
>>> out2 = ops.is_nonzero(x2)
>>> print(out2)
True