TUTORIALAI 与数据科学FETCHED
PyTorch torch.hypot 函数
PyTorch torch.hypot 函数 Pytorch torch 参考手册 torch.hypot 是 PyTorch 中用于计算直角三角形斜边长度的函数,即 sqrt(a^2 + b^2)。 函数定义 torch.hypot(input, other, out=None) 使用示例 实例 [mycode4 type='python'] import torch # 创建两个直角边 a ..
更新于 2026/7/16
教程详情页默认 noindex。
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)
# 创建两个直角边
a = torch.tensor([3.0, 5.0])
b = torch.tensor([4.0, 12.0])
# 计算斜边长度
c = torch.hypot(a, b)
print("斜边:", c)
输出结果为:
斜边: tensor([ 5., 13.])
Pytorch torch 参考手册