python math.hypot()方法,返回欧几里得范数
math.hypot()语法
hypot(x, y, /)
python源码中对hypot()方法的介绍:
Return the Euclidean distance, sqrt(x*x + y*y).
即,python的math模块中的hypot()方法,可以返回参数指定的坐标(x,y)相对于直角坐标系中原点的欧氏距离,或者说是欧几里得范数。欧氏距离在机器学习当中有广泛的应用,比如K近邻分类算法等等。
hypot()参数
参数 | 描述 |
---|---|
x | real number,比如python的int或float类型值 |
y | real number,比如python的int或float类型值 |
返回值
sqrt(x*x + y*y),即x和y的平方和的平方根,为python浮点数类型值。
math.hypot()方法实例代码
>>> import math
>>> math.hypot(1.5,2)
2.5
>>> math.hypot('3','3')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be real number, not str