torch.sgn
- torch.sgn(input, *, out=None) → Tensor
-
此函数是 torch.sign() 在复数张量上的扩展。它计算一个新张量,该张量的元素具有与
input
对应元素相同的相位角,并且对于复数张量其绝对值(即幅度)为 1。对于非复数张量,此函数等同于 torch.sign()。$\text{out}_{i} = \begin{cases} 0 & |\text{{input}}_i| == 0 \\ \frac{{\text{{input}}_i}}{|{\text{{input}}_i}|} & \text{otherwise} \end{cases}$示例:
>>> t = torch.tensor([3+4j, 7-24j, 0, 1+2j]) >>> t.sgn() tensor([0.6000+0.8000j, 0.2800-0.9600j, 0.0000+0.0000j, 0.4472+0.8944j])