PyTorch torch.sgn Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.sgnis 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 Example

Example

import torch

# Return sign vector element-wise
x = torch.tensor([-2.0, 0.0, 3.0])
result = torch.sgn(x)
print(result)

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions