torch.sgn¶ torch.sgn(input, *, out=None) → Tensor¶ 此函数是 torch.sign() 对复数张量的扩展。它计算一个新的张量,该张量的元素与 input 中对应元素的角度相同,对于复数张量,其绝对值(即幅度)为 1,对于非复数张量,则等效于 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, 可选) – 输出张量。 示例 >>> 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])