Shortcuts

torch.neg

torch.neg(input, *, out=None) 张量

返回一个新的张量,其中包含 input 元素的负值。

out=1×input\text{out} = -1 \times \text{input}
Parameters

输入 (张量) – 输入张量。

Keyword Arguments

输出 (张量, 可选) – 输出张量。

示例:

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