mindspore.ops.sgn

mindspore.ops.sgn(input)[source]

Extension of mindspore.ops.sign() in complex domain. For real number input, this function is the same as mindspore.ops.sign(). For complex input, this function is calculated according to the following formula.

\[\begin{split}\text{out}_{i} = \begin{cases} 0 & |\text{input}_i| == 0 \\ \frac{{\text{input}_i}}{|{\text{input}_i}|} & \text{otherwise} \end{cases}\end{split}\]
Parameters

input (Tensor) – The input value.

Returns

Tensor, the sgn of input.

Raises

TypeError – If input is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> from mindspore import ops
>>> input = ms.Tensor([[3 + 4j, 7 - 24j, 0, 6 + 8j, 8], [15 + 20j, 7 - 24j, 0, 3 + 4j, 20]], dtype=ms.complex64)
>>> output = ops.sgn(input)
>>> print(output)
[[0.6 +0.8j  0.28-0.96j 0.  +0.j   0.6 +0.8j  1.  +0.j  ]
 [0.6 +0.8j  0.28-0.96j 0.  +0.j   0.6 +0.8j  1.  +0.j  ]]