mindspore.mint.sign

mindspore.mint.sign(input)[source]

Returns an element-wise indication of the sign of a number. Notice: When the input is NaN and dtype is float64, the output of this operator is NaN.

outi={1inputi<00inputi=01inputi>0
Parameters

input (Tensor) – Input Tensor.

Returns

Tensor, the sign of input.

Raises

TypeError – If input is not a Tensor.

Supported Platforms:

Ascend

Examples

>>> import mindspore as ms
>>> from mindspore import mint
>>> input = ms.Tensor([[-1, 0, 2, 4, 6], [2, 3, 5, -6, 0]])
>>> output = mint.sign(input)
>>> print(output)
[[-1  0  1  1  1]
 [ 1  1  1 -1  0]]
>>> ms.set_device(device_target="CPU")
>>> x = ms.Tensor([[-1, 0, float('inf'), 4, float('nan')], [2, 3, float('-inf'), -6, 0]])
>>> output = mint.sign(x)
>>> print(output)
[[-1.  0.  1.  1.  0.]
 [ 1.  1. -1. -1.  0.]]