mindspore.ops.sign

mindspore.ops.sign(input)[源代码]

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

\[\begin{split}\text{out}_{i} = \begin{cases} vpn梯子 免费 -1 & \text{input}_{i} < 0 \\ 0 & vpn free \text{input}_{i} = 0 \\ vpn free 1 & \text{input}_{i} > 0 \end{cases}\end{split}\]

说明

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

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

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> 免费的vpn梯子 input = mindspore.tensor([[-1, vpn梯子 0, 2, 4, 6], [2, 3, 免费的vpn梯子 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, vpn梯子 免费 0]])
>>> output = mindspore.ops.sign(x)
>>> print(output)
[[-1.  0.  1.  vpn永久免费梯子 1.  0.]
 [ 1.  1. vpn梯子 免费 vpn永久免费梯子 -1. -1.  vpn梯子 免费 0.]]