欧几里得距离
最编程
2024-06-16 22:51:25
...
定义
在欧几里得空间中,点 x = (x1,...,xn) 和 y = (y1,...,yn)之间的欧氏距离为
向量 x 的自然长度,即该点到原点的距离为
它是一个纯数值。在欧几里得度量下,两点之间线段最短。
Python实现
euclidean_distance.py
from numpy import tile
def point_distance(point_a, point_b):
d_value = point_b - point_a
return calculate_distance(d_value)
def point_data_set_distance(point, data_set):
data_set_size = data_set.shape[0]
d_value = tile(point, (data_set_size, 1)) - data_set
return calculate_distance(d_value, True)
def calculate_distance(d, is_set=False):
axis = 1 if is_set else 0
return ((d ** 2).sum(axis=axis)) ** 0.5
计算点[1,2,3]到点[5,5,5]之间的距离
>>> from numpy import array
>>> a = array([1,2,3])
>>> b = array([5,5,5])
>>> from euclidean_distance import point_distance
>>> point_distance(a,b)
5.3851648071345037
计算点[1,1]到数据集[[2,2],[3,3],[4,4]]中每个点的距离
>>> from numpy import array
>>> a = array([1,1])
>>> b = array([[2,2],[3,3],[4,4]])
>>> from euclidean_distance import point_data_set_distance
>>> point_data_set_distance(a,b)
array([ 1.41421356, 2.82842712, 4.24264069])
推荐阅读
-
如何计算电机加速时间和距离的公式
-
创新3D目标追踪技术:运用多重感应器整合的加权几何距离连结法 - 二维与三维目标追踪
-
两种方法让你轻松调整table表格单元格间的距离
-
在HTML中使用a标签实现锚点定位并设置距离顶部的偏移量
-
我做了一个在手机灵动岛&锁屏看实时网速/步数/下班倒计时/跑步距离/照片/待办/倒计时/手机使用次数/帧率...的软件
-
用GeoTools快速算出两地之间的距离
-
十四章:机器人操作模拟实战 - 机器人动作控制与行走距离读取展示
-
OpenCV入门教程笔记(1):解决OpenCV报错 "libpng错误:IDAT后面的距离无效过远" 的问题
-
基于反距离加权的插值技术
-
神经网络配合激光雷达测距数据集:新方法探索距离测量技术