快捷方式

torch.neg

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

返回一個新張量,其元素是 input 張量元素的負值。

out=1×input\text{out} = -1 \times \text{input}
引數

input (Tensor) – 輸入張量。

關鍵字引數

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

示例

>>> a = torch.randn(5)
>>> a
tensor([ 0.0090, -0.2262, -0.0682, -0.2866,  0.3940])
>>> torch.neg(a)
tensor([-0.0090,  0.2262,  0.0682,  0.2866, -0.3940])

文件

訪問 PyTorch 的全面開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深度教程

檢視教程

資源

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

檢視資源