mindspore.mint.sign

View Source On Gitee
mindspore.mint.sign(input)[source]

Return an element-wise indication of the sign of a number.

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

Note

When the input is NaN and dtype is float64, the output of this operator is NaN.

Parameters

input (Tensor) – The input tensor.

Returns

Tensor

Supported Platforms:

Ascend

Examples

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