Shortcuts

torch.sub

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

input 中减去按 alpha 缩放的 other

outi=inputialpha×otheri\text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i

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

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

  • 其他 (Tensor数字) – 要从 input 中减去的张量或数字。

Keyword Arguments
  • alpha (数字) – other 的乘数。

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

示例:

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