torch.sgn¶ torch.sgn(input, *, out=None) → Tensor¶ 此函数是 torch.sign() 函数对复数张量的扩展。它计算一个新的张量,其元素对于复数张量具有与对应 input 元素相同的角度和为一的绝对值(即幅度),对于非复数张量则等同于 torch.sign()。 outi={0∣inputi∣==0inputi∣inputi∣otherwise\text{out}_{i} = \begin{cases} 0 & |\text{{input}}_i| == 0 \\ \frac{{\text{{input}}_i}}{|{\text{{input}}_i}|} & \text{otherwise} \end{cases} outi={0∣inputi∣inputi∣inputi∣==0otherwise 参数 input (Tensor) – 输入张量。 关键字参数 out (Tensor, optional) – 输出张量。 示例 >>> 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])