PyTorch torch.hypot function
PyTorch torch reference manual
torch.hypot A function in PyTorch for computing the hypotenuse length of a right triangle, i.e. sqrt(a^2 + b^2).
Function definition
torch.hypot(input, other, out=None)
Usage examples
Example
import
torch
Create the two legs
a
=
torch.
tensor
(
[
3.0
,
5.0
]
)
b
=
torch.
tensor
(
[
4.0
,
12.0
]
)
Compute the hypotenuse length
c
=
torch.
hypot
(
a
,
b
)
(
"Hypotenuse:"
,
c
)
The output is:
斜边: tensor([ 5., 13.])