TUTORIALAI & dataFETCHED
PyTorch torch.sub 函数
PyTorch torch.sub 函数 Pytorch torch 参考手册 torch.sub 是 PyTorch 中用于执行逐元素减法的函数。 函数定义 torch.sub(input, other, out=None) 使用示例 实例 [mycode4 type='python'] import torch # 逐元素相减 x = torch.tensor([5.0, 6.0, 7.0]..
Updated 7/16/2026
Tutorial detail pages default to noindex.
PyTorch torch.sub 函数
torch.sub 是 PyTorch 中用于执行逐元素减法的函数。
函数定义
torch.sub(input, other, out=None)
使用示例
实例
import torch
# 逐元素相减
x = torch.tensor([5.0, 6.0, 7.0])
y = torch.tensor([1.0, 2.0, 3.0])
result = torch.sub(x, y)
print(result)
# 逐元素相减
x = torch.tensor([5.0, 6.0, 7.0])
y = torch.tensor([1.0, 2.0, 3.0])
result = torch.sub(x, y)
print(result)
Pytorch torch 参考手册