torch.sub¶
- torch.sub(input, other, *, alpha=1, out=None) Tensor ¶
从
input
中减去other
,并按alpha
缩放。支持广播到公共形状,类型提升和整数、浮点数和复数输入。
- 参数:
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])