mindspore.ops.Sign

View Source On Gitee
class mindspore.ops.Sign[source]

Performs sign on the tensor element-wise. Notice: when the input is NaN and dtype is float64, the output of this operator is NaN.

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

Outputs:

Tensor, has the same shape and dtype as the x.

Raises

TypeError – If x is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

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