快捷鍵

torch.sign

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

傳回一個新的 tensor,其元素為 input 的正負號。

outi=sgn(inputi)\text{out}_{i} = \operatorname{sgn}(\text{input}_{i})
參數

input (Tensor) – 輸入張量。

關鍵字參數

out (Tensor, optional) – 輸出張量 (可選)。

範例

>>> a = torch.tensor([0.7, -1.2, 0., 2.3])
>>> a
tensor([ 0.7000, -1.2000,  0.0000,  2.3000])
>>> torch.sign(a)
tensor([ 1., -1.,  0.,  1.])

文件

取得 PyTorch 的完整開發者文件

檢視文件

教學

取得針對初學者和進階開發者的深入教學

檢視教學

資源

尋找開發資源並獲得您問題的解答

檢視資源