PyTorch torch.sub 函数

约 254 字 更新于 2026-11-18 5iyo.com

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)