快捷方式

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) – 输入 tensor。

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

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

  • out (Tensor可选) – 输出 tensor。

示例

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

文档

查阅 PyTorch 的全面开发者文档

查看文档

教程

获取适合初学者和高级开发者的深入教程

查看教程

资源

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

查看资源