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])
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])