PyTorch torch.sgn function
PyTorch torch reference manual
torch.sgn is a function in PyTorch used to return the sign vector element-wise. For complex numbers, it returns the unit complex number.
Function definition
torch.sgn(input, out=None)
Usage examples
Example
import
torch
Return the sign vector element-wise
x
=
torch.
tensor
(
[
2.0
,
0.0
,
3.0
]
)
result
=
torch.
sgn
(
x
)
(
result
)