PyTorch torch.hypot 函数

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

PyTorch torch.hypot 函数


torch.hypot 是 PyTorch 中用于计算直角三角形斜边长度的函数,即 sqrt(a^2 + b^2)。

函数定义

torch.hypot(input, other, out=None)

使用示例

实例

import torch

# 创建两个直角边
a = torch.tensor([3.0, 5.0])
b = torch.tensor([4.0, 12.0])

# 计算斜边长度
c = torch.hypot(a, b)
print("斜边:", c)

输出结果为:

斜边: tensor([ 5., 13.])