评价此页

torch.sub#

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

input 中减去 other,并乘以 alpha

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

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

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

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

关键字参数
  • alpha (Number) – other 的乘数。

  • out (Tensor, optional) – 输出张量。

示例

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