当前位置:网站首页>[data mining] task 1: distance calculation
[data mining] task 1: distance calculation
2022-07-03 01:38:00 【zstar-_】
subject
Given two tuples (22,1,42,10) and (20,0,36,8) The object of expression
(a) Calculate the Euclidean distance between these two objects ;
(b) Calculate the Manhattan distance between the two objects ;
(c) Use q=3, Calculate the Minkowski distance between the two objects
(d) Calculates the supremum distance between two objects
Create objects
a = (22, 1, 42, 10)
b = (20, 0, 36, 8)
Euclidean distance
import numpy as np
def euclidean(x, y):
return np.sqrt(sum((x[i] - y[i]) ** 2 for i in range(len(x))))
euclidean(a, b)
6.708203932499369
Manhattan distance
def manhattan(x, y):
return sum(np.abs(x[i] - y[i]) for i in range(len(x)))
manhattan(a, b)
11
Minkowski distance
def minkowski(x, y, p):
return sum(np.abs(x[i] - y[i]) ** p for i in range(len(x))) ** (1 / p)
minkowski(a, b, 3)
6.153449493663682
Supremum distance
def Supremum(x, y):
return np.abs(max(x) - max(y))
Supremum(a, b)
6
边栏推荐
- Dotconnect for PostgreSQL data provider
- How is the mask effect achieved in the LPL ban/pick selection stage?
- MySQL - database query - condition query
- d,ldc構建共享庫
- tp6快速安装使用MongoDB实现增删改查
- Mathematical knowledge: step Nim game game game theory
- Vim 9.0正式发布!新版脚本执行速度最高提升100倍
- Three core issues of concurrent programming - "deep understanding of high concurrent programming"
- Look at how clothing enterprises take advantage of the epidemic
- Telecom Customer Churn Prediction challenge
猜你喜欢
【面试题】1369- 什么时候不能使用箭头函数?
Using tensorboard to visualize the model, data and training process
Androd gradle's substitution of its use module dependency
[shutter] animation animation (animatedbuilder animation use process | create animation controller | create animation | create components for animation | associate animation with components | animatio
Steps to obtain SSL certificate private key private key file
Qtablewidget lazy load remaining memory, no card!
MySQL - database query - basic query
Dotconnect for PostgreSQL data provider
Installation and use of serial port packet capturing / cutting tool
【C语言】指针与数组笔试题详解
随机推荐
音程的知识的总结
View of MySQL
Arduino dy-sv17f automatic voice broadcast
C语言课程信息管理系统
软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
【面试题】1369- 什么时候不能使用箭头函数?
Dotconnect for PostgreSQL data provider
d,ldc構建共享庫
[技术发展-23]:DSP在未来融合网络中的应用
What is tone. Diao's story
After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9
Uniapp component -uni notice bar notice bar
How is the mask effect achieved in the LPL ban/pick selection stage?
并发编程的三大核心问题 -《深入理解高并发编程》
C#应用程序界面开发基础——窗体控制(3)——文件类控件
[Androd] Gradle 使用技巧之模块依赖替换
Thinkphp+redis realizes simple lottery
VIM 9.0 is officially released! The execution speed of the new script can be increased by up to 100 times
How is the mask effect achieved in the LPL ban/pick selection stage?
[androd] module dependency replacement of gradle's usage skills