评价此页

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