torch.sgn

torch.sgn(input, *, out=None) → Tensor

For complex tensors, this function returns a new tensor whose elemants have the same angle as that of the elements of input and absolute value 1. For a non-complex tensor, this function returns the signs of the elements of input (see torch.sign()).

outi=0\text{out}_{i} = 0 , if inputi==0|{\text{{input}}_i}| == 0 outi=inputiinputi\text{out}_{i} = \frac{{\text{{input}}_i}}{|{\text{{input}}_i}|} , otherwise

Parameters

input (Tensor) – the input tensor.

Keyword Arguments

out (Tensor, optional) – the output tensor.

Example:

>>> x=torch.tensor([3+4j, 7-24j, 0, 1+2j])
>>> x.sgn()
tensor([0.6000+0.8000j, 0.2800-0.9600j, 0.0000+0.0000j, 0.4472+0.8944j])

© 2019 Torch Contributors
Licensed under the 3-clause BSD License.
https://pytorch.org/docs/1.8.0/generated/torch.sgn.html