快捷方式

torch.sgn

torch.sgn(input, *, out=None) Tensor

此函式是 torch.sign() 函式對複數張量的擴充套件。它計算一個新的張量,其元素對於複數張量具有與對應 input 元素相同的角度和為一的絕對值(即幅度),對於非複數張量則等同於 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}
引數

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

文件

訪問 PyTorch 全面的開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源