torch.sub

torch.sub(input, other, *, alpha=1, out=None) Tensor

input中减去按alpha缩放后的other

$\text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i$

支持广播到公共形状类型提升,以及整数、浮点和复数输入。

参数
  • input (Tensor) – 需要输入的张量。

  • other (TensorNumber) – 需要从input中减去的张量或数字。

关键字参数
  • alpha (Number) – 用于表示 other 的乘数值。

  • out (Tensor, 可选) – 指定输出张量。

示例:

>>> a = torch.tensor((1, 2))
>>> b = torch.tensor((0, 1))
>>> torch.sub(a, b, alpha=2)
tensor([1, 0])
本页目录