mindspore.ops.sign

查看源文件
mindspore.ops.sign(input)[源代码]

按sign公式逐元素计算输入tensor。

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

说明

在输入为NaN且数据类型为float64时,该算子计算结果为NaN。

参数:
  • input (Tensor) - 输入tensor。

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> input = mindspore.tensor([[-1, 0, 2, 4, 6], [2, 3, 5, -6, 0]])
>>> output = mindspore.ops.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.ops.sign(x)
>>> print(output)
[[-1.  0.  1.  1.  0.]
 [ 1.  1. -1. -1.  0.]]