torch.hypot

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

根据直角三角形的两个直角边,计算并返回斜边的长度。

$\text{out}_{i} = \sqrt{\text{input}_{i}^{2} + \text{other}_{i}^{2}}$

代码中的 inputother 形状必须是 可广播的

参数
  • input (Tensor) – 输入的第一个张量

  • other (Tensor) – 输入的第二个张量

关键字参数

out (Tensor, 可选) – 指定输出张量。

示例:

>>> a = torch.hypot(torch.tensor([4.0]), torch.tensor([3.0, 4.0, 5.0]))
tensor([5.0000, 5.6569, 6.4031])
本页目录