mindspore.mint.sign
- mindspore.mint.sign(input)[source]
Returns an element-wise indication of the sign of a number. Notice: When the input is NaN and dtype is float64, the output of this operator is NaN.
\[\begin{split}\text{out}_{i} = \begin{cases} -1 & \text{input}_{i} < 0 \\ 0 & \text{input}_{i} = 0 \\ 1 & \text{input}_{i} > 0 \end{cases}\end{split}\]- Parameters
input (Tensor) – Input Tensor.
- Returns
Tensor, the sign of input.
- Raises
TypeError – If input is not a Tensor.
- Supported Platforms:
Ascend
Examples
>>> import mindspore as ms >>> from mindspore import mint >>> input = ms.Tensor([[-1, 0, 2, 4, 6], [2, 3, 5, -6, 0]]) >>> output = mint.sign(input) >>> print(output) [[-1 0 1 1 1] [ 1 1 1 -1 0]] >>> ms.set_context(device_target="CPU") >>> x = ms.Tensor([[-1, 0, float('inf'), 4, float('nan')], [2, 3, float('-inf'), -6, 0]]) >>> output = mint.sign(x) >>> print(output) [[-1. 0. 1. 1. 0.] [ 1. 1. -1. -1. 0.]]