Shortcuts

torch.sgn

torch.sgn(input, *, out=None) 张量

此函数是 torch.sign() 对复数张量的扩展。 它计算一个新张量,其元素具有 与 input 对应元素相同的角,并且 复数张量的绝对值(即幅度)为1, 对于非复数张量等同于 torch.sign()。

outi={0inputi==0inputiinputiotherwise\text{out}_{i} = \begin{cases} 0 & |\text{{input}}_i| == 0 \\ \frac{{\text{{input}}_i}}{|{\text{{input}}_i}|} & \text{otherwise} \end{cases}
Parameters

输入 (张量) – 输入张量。

Keyword Arguments

输出 (张量, 可选) – 输出张量。

示例:

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