評價此頁

torch.neg#

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

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

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

input (Tensor) – 輸入張量。

關鍵字引數

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

示例

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