Python/ref math hypot
来自菜鸟教程
<languages />
Python math.hypot()方法
例
找到已知垂直和底角的直角三角形的斜边:
#Import math Library
import math
#set perpendicular and base
parendicular = 10
base = 5
#print the hypotenuse of a right-angled
triangle
print(math.hypot(parendicular, base))
定义和用法
The
math.hypot()
方法返回欧几里得范数。欧几里得范数是从原点到给定坐标的距离。
在Python 3.8之前的版本中,此方法仅用于查找直角三角形的斜边:sqrt(x * x + y * y)。
从Python 3.8开始,此方法也用于计算欧几里得范数。对于n维情况,假定传递的坐标类似于(x1,x2,x3,...,xn)。因此,从原点开始的欧几里得长度是通过sqrt(x1 * x1 + x2 * x2 + x3 * x3 ....xn * xn)。
句法
math.hypot(x1, x2, x3, ..., xn)
参数值
| 参数 | 描述 |
|---|---|
| x1
, x2 , x3 ,..., xn |
需要。两个或更多个代表坐标的点 |
技术细节
| 返回值: | A
|
| 变更记录: | 从3.8开始:还支持
n 维点。早期版本仅支持二维点 |
更多例子
例
找到给定点的欧几里得范数:
#Import math Library
import math
#print the Euclidean norm for
the given points
print(math.hypot(10, 2, 4, 13))
print(math.hypot(4, 7, 8))
print(math.hypot(12, 14))