mindspore.ops.Sign

class mindspore.ops.Sign(*args, **kwargs)[source]

Performs sign on the tensor element-wise.

\[sign(x) = \begin{cases} -1, &if\ x < 0 \cr 0, &if\ x = 0 \cr 1, &if\ x > 0\end{cases}\]
Inputs:
  • input_x (Tensor) - The input tensor.

Outputs:

Tensor, has the same shape and type as the input_x.

Raises

TypeError – If input_x is not a Tensor.

Supported Platforms:

Ascend CPU

Examples

>>> input_x = Tensor(np.array([[2.0, 0.0, -1.0]]), mindspore.float32)
>>> sign = ops.Sign()
>>> output = sign(input_x)
>>> print(output)
[[ 1.  0. -1.]]