当前位置:网站首页>距离度量 —— 欧式距离(Euclidean Distance)
距离度量 —— 欧式距离(Euclidean Distance)
2022-06-11 10:42:00 【繁依Fanyi】
Python学习系列文章:目录

概述
欧式距离,也称为 欧几里得距离,是我们从小学、初中、高中等等乃至现在都会用到的距离度量。
“两点之间线段最短” 大家都学过吧,这里只不过给换了一个高大上的英文名字,就是我们在小初高等试卷上计算距离的那个公式
计算公式
① 二维平面上的欧式距离
假设 二维平面 内有两点: a ( x 1 , y 1 ) a(x_{1},y_{1}) a(x1,y1) 与 b ( x 2 , y 2 ) b(x_{2},y_{2}) b(x2,y2)
则二维平面的距离公式为:
d 12 = ( x 1 − x 2 ) 2 + ( y 1 − y 2 ) 2 d_{12}=\sqrt{(x_{1}-x_{2})^2+(y_{1}-y_{2})^2} d12=(x1−x2)2+(y1−y2)2

举个例子,就比如上图的 A ( 2 , 2 ) A(2,2) A(2,2) 与 B ( 6 , 6 ) B(6,6) B(6,6) 两点,计算 A B AB AB 两点的距离为:
d A B = ( 6 − 2 ) 2 + ( 6 − 2 ) 2 = 4 2 + 4 2 = 4 2 \begin{aligned} d_{AB} &=\sqrt{(6-2)^2+(6-2)^2}\\ &=\sqrt{4^2+4^2}\\ &= 4\sqrt{2} \end{aligned} dAB=(6−2)2+(6−2)2=42+42=42
② 三维空间上的欧式距离
假设 三维空间 内有两点: a ( x 1 , y 1 , z 1 ) a(x_{1},y_{1},z_{1}) a(x1,y1,z1) 与 b ( x 2 , y 2 , z 2 ) b(x_{2},y_{2},z_{2}) b(x2,y2,z2)
则三维空间的距离公式为:
d 12 = ( x 1 − x 2 ) 2 + ( y 1 − y 2 ) 2 + ( z 1 − z 2 ) 2 d_{12}=\sqrt{(x_{1}-x_{2})^2+(y_{1}-y_{2})^2+(z_{1}-z_{2})^2} d12=(x1−x2)2+(y1−y2)2+(z1−z2)2

举个例子,比如上图的 A ( 0 , 0 , 4 ) A(0,0,4) A(0,0,4) 与 B ( 0 , 2 , 0 ) B(0,2,0) B(0,2,0) 两点,计算 A B AB AB 两点的距离为:
d A B = ( 0 − 0 ) 2 + ( 0 − 2 ) 2 + ( 4 − 0 ) 2 = 0 + 4 + 16 = 2 5 \begin{aligned} d_{AB} &=\sqrt{(0-0)^2+(0-2)^2+(4-0)^2}\\ &=\sqrt{0+4+16}\\ &= 2\sqrt{5} \end{aligned} dAB=(0−0)2+(0−2)2+(4−0)2=0+4+16=25
③ n维空间上的欧式距离
假设 n维空间 内有两点: a ( x 11 , x 12 , . . . , x 1 n ) a(x_{11},x_{12},...,x_{1n}) a(x11,x12,...,x1n) 与 b ( x 21 , y 22 , . . . , z 2 n ) b(x_{21},y_{22},...,z_{2n}) b(x21,y22,...,z2n)
则n维空间的距离公式为:
d 12 = ∑ k = 1 n ( x 1 k − x 2 k ) 2 d_{12}=\sqrt{\sum_{k=1}^n(x_{1k}-x_{2k})^2} d12=k=1∑n(x1k−x2k)2
同理,n 维空间也是,将对应的向量作以上运算即可。(n 维的画不出来,需要用其他形式表示,就像下图一样)。


边栏推荐
- 修复UICollectionView 没有到达底部安全区的问题
- 白屏时间、首屏时间
- 恋爱时将房屋一半产权登记在女方名下,分手后想要回
- MySQL (IX)
- Online files are not transferred to Base64
- 基于位置服务(LBS)的SSM的框架实现的兴趣社交软件平台设计与实现
- 34. 在排序数组中查找元素的第一个和最后一个位置 ●●
- 使用 Hystrix 实现微服务的容错处理
- 5.读取指定路径名-dirname
- Taking the cooperation between different banks as an example, the construction of small program ecology
猜你喜欢

杰理之获取 BLE OTA 双备份升级(只能用于 4Mbits 以上的芯片)【篇】
![FPGA infrastructure [reference ug998]](/img/68/7eee191c52029dc140168bdb64b947.png)
FPGA infrastructure [reference ug998]

MySQL (IX)

Remote monitoring project offline log specification

MySQL下载安装使用-完整详细步骤

NFT产品是有生命的

Leetcode 1961. Check whether the string is an array prefix

Xilinx pin constraint file xdc

Leetcode 1995. 统计特殊四元组(暴力枚举)

地铁路线图云开发小程序源码和配置教程
随机推荐
Install MySQL version 5.7 or above on windows (install in compressed package)
金仓数据库KingbaseES中的PL/SQL 编译检查
NFT产品是有生命的
Use of kingbasees UDP monitoring tool for gold warehouse database
Kingbasees create database objects in batch
Implementation of competition scoring system based on C language
Linker and linker options, runtime libraries and runtime library settings, configuration settings, build process and methods
修复UICollectionView 没有到达底部安全区的问题
白屏时间、首屏时间
Window management learn more about windowmanagerservice
Beginning an excellent emlog theme
Wechat cloud development al short video one click face changing applet source code
Pl/sql compilation check in kingbasees
金仓数据库KingbaseES中的sys_checksums坏块检测功能
1712. 将数组分成三个子数组的方案数 ●●
云开发mbti人格类型测试助手微信小程序源码
Why is Web3 a game changer for the "creator economy"
5.读取指定路径名-dirname
MySQL foundation part common constraints summary part 2
SAP Spartacus Reference App Structure