Python math.hypot() Method
Python math.hypot()The method returns the Euclidean norm.
The Euclidean norm is the distance from the origin to the given coordinates.
The Euclidean metric, also known as Euclidean distance, refers to the "ordinary" (i.e., straight-line) distance between two points in Euclidean space.
Before Python 3.8, this method was used to find the hypotenuse of a right triangle:sqrt(x*x + y*y)。
Since Python 3.8, this method is also used to calculate the Euclidean norm. For the n-dimensional case, the passed coordinates are assumed to be similar to(x1, x2, x3, ..., xn), and the Euclidean length from the origin is calculated bysqrt(x1*x1 + x2*x2 +x3*x3 .... xn*xn).
Python Version: 3.8
Syntax
The syntax of the math.hypot() method is as follows:
math.hypot(x1, x2, x3, ..., xn)
Parameter Description:
- x1, x2, x3, ..., xn-- Required, represents multiple coordinate points.
Return Value
A floating-point value representing the Euclidean distance from n inputs to the origin, or the hypotenuse of a right triangle with two inputs.
Example
The following example calculates the hypotenuse of a right triangle:
Example
import math
# Set the perpendicular line and base
parendicular = 10
base = 5
# Output the hypotenuse of the right triangle
print(math.hypot(parendicular, base))
Output result:
11.180339887498949
The following example calculates the Euclidean norm of given coordinates:
Example
import math
# Output the Euclidean norm of the given coordinates
print(math.hypot(10, 2, 4, 13))
print(math.hypot(4, 7, 8))
print(math.hypot(12, 14))
Output result:
17.0 11.357816691600547 18.439088914585774Other Extensions
Python math Module