快捷方式

torch.sub

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

input 中减去按 alpha 缩放的 other

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, 可选) – 输出张量。

示例

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

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深度教程

查看教程

资源

查找开发资源并获得问题解答

查看资源