当前位置:网站首页>【数据挖掘】任务1:距离计算
【数据挖掘】任务1:距离计算
2022-07-03 01:09:00 【zstar-_】
题目
给定两个被元组(22,1,42,10)和(20,0,36,8)表示的对象
(a)计算这两个对象之间的欧几里得距离;
(b)计算这两个对象之间的曼哈顿距离;
(c)使用q=3,计算这两个对象之间的闵可夫斯基距离
(d)计算着两个对象之间的上确界距离
创建对象
a = (22, 1, 42, 10)
b = (20, 0, 36, 8)
欧氏距离
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
曼哈顿距离
def manhattan(x, y):
return sum(np.abs(x[i] - y[i]) for i in range(len(x)))
manhattan(a, b)
11
闵可夫斯基距离
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
上确界距离
def Supremum(x, y):
return np.abs(max(x) - max(y))
Supremum(a, b)
6
边栏推荐
- Druid database connection pool
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
- Top ten regular spot trading platforms 2022
- Leetcode 2097 - Legal rearrangement of pairs
- 海量数据冷热分离方案与实践
- VIM 9.0 is officially released! The execution speed of the new script can be increased by up to 100 times
- Arduino DY-SV17F自动语音播报
- 【我的OpenGL学习进阶之旅】关于欧拉角、旋转顺序、旋转矩阵、四元数等知识的整理
- [shutter] animation animation (the core class of shutter animation | animation | curvedanimation | animationcontroller | tween)
- 【第29天】给定一个整数,请你求出它的因子数
猜你喜欢
【面试题】1369- 什么时候不能使用箭头函数?
Database SQL language 01 where condition
Scheme and practice of cold and hot separation of massive data
Telecom Customer Churn Prediction challenge
MySQL foundation 05 DML language
给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。【剑指Offer】
LeetCode 987. Vertical order transverse of a binary tree - Binary Tree Series Question 7
Top ten regular spot trading platforms 2022
海量数据冷热分离方案与实践
【数据挖掘】任务2:医学数据库MIMIC-III数据处理
随机推荐
并发编程的三大核心问题 -《深入理解高并发编程》
QTableWidget懒加载剩内存,不卡!
Androd gradle's substitution of its use module dependency
MySQL foundation 04 MySQL architecture
MySQL basics 03 introduction to MySQL types
Kivy tutorial - example of using Matplotlib in Kivy app
Steps to obtain SSL certificate private key private key file
[Arduino experiment 17 L298N motor drive module]
tp6快速安装使用MongoDB实现增删改查
SwiftUI 组件大全之使用 SceneKit 和 SwiftUI 构建交互式 3D 饼图(教程含源码)
MySQL foundation 07-dcl
Do not log in or log in to solve the problem that the Oracle database account is locked.
Niu Ke swipes questions and clocks in
[机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道
[day 29] given an integer, please find its factor number
[untitled]
2022 cable crane driver examination registration and cable crane driver certificate examination
Mathematical Knowledge: Steps - Nim Games - Game Theory
ThinkPHP+Redis实现简单抽奖
【数据挖掘】任务2:医学数据库MIMIC-III数据处理