PyTorch torch.div 函数

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

PyTorch torch.div 函数


torch.div 是 PyTorch 中用于执行逐元素除法的函数。

函数定义

torch.div(input, other, rounding_mode, out)

使用示例

实例

import torch

a = torch.tensor([10, 20, 30])
b = torch.tensor([2, 4, 5])

# 逐元素除法
c = torch.div(a, b)
print(c)

输出结果为:

tensor([5., 5., 6.])