当前位置:网站首页>[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
边栏推荐
猜你喜欢

并发编程的三大核心问题 -《深入理解高并发编程》

【面试题】1369- 什么时候不能使用箭头函数?

Leetcode skimming questions_ Sum of two numbers II - enter an ordered array

Steps to obtain SSL certificate private key private key file

【数据挖掘】任务2:医学数据库MIMIC-III数据处理
![[shutter] animation animation (animatedbuilder animation use process | create animation controller | create animation | create components for animation | associate animation with components | animatio](/img/32/fa1263d9a2e5f77b0434fce1912cb2.gif)
[shutter] animation animation (animatedbuilder animation use process | create animation controller | create animation | create components for animation | associate animation with components | animatio

MySQL --- 数据库查询 - 条件查询

C application interface development foundation - form control (3) - file control

Work experience of a hard pressed programmer
![[principles of multithreading and high concurrency: 2. Solutions to cache consistency]](/img/ce/5c41550ed649ee7cada17b0160f739.jpg)
[principles of multithreading and high concurrency: 2. Solutions to cache consistency]
随机推荐
High resolution network (Part 1): Principle Analysis
[技术发展-23]:DSP在未来融合网络中的应用
[QT] encapsulation of custom controls
What is tone. Diao's story
简易分析fgui依赖关系工具
C语言课程信息管理系统
Vim 9.0正式发布!新版脚本执行速度最高提升100倍
STM32 - introduction of external interrupts exti and NVIC
Mathematical knowledge: step Nim game game game theory
Look at how clothing enterprises take advantage of the epidemic
Force buckle 204 Count prime
leetcode刷题_两数之和 II - 输入有序数组
C#应用程序界面开发基础——窗体控制(4)——选择类控件
Why is it not recommended to use BeanUtils in production?
C language course information management system
【C语言】指针与数组笔试题详解
The meaning of wildcard, patsubst and notdir in makefile
ThinkPHP+Redis实现简单抽奖
View of MySQL
Leetcode 2097 - Legal rearrangement of pairs