PyTorch torch.hypot Function
Pytorch torch Reference Manual
torch.hypotIt is a function in PyTorch used to calculate the length of the hypotenuse of a right triangle, i.e., sqrt(a^2 + b^2).
Function Definition
torch.hypot(input, other, out=None)
Usage Example
Example
import torch
# Create two right-angle sides
a = torch.tensor([3.0, 5.0])
b = torch.tensor([4.0, 12.0])
# Calculate the hypotenuse length
c = torch.hypot(a, b)
print("Hypotenuse:", c)
# Create two right-angle sides
a = torch.tensor([3.0, 5.0])
b = torch.tensor([4.0, 12.0])
# Calculate the hypotenuse length
c = torch.hypot(a, b)
print("Hypotenuse:", c)
The output result is:
斜边: tensor([ 5., 13.])
Other Extensions