• 文档 >
  • torch >
  • torch.sub
快捷键

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 (Tensor 或 Number) – 要从 input 中减去的张量或数字。

关键字参数:
  • alpha(数字)- other 的乘数。

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

示例:

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

© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源