-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBk7_Ch03_06.py
More file actions
27 lines (20 loc) · 714 Bytes
/
Bk7_Ch03_06.py
File metadata and controls
27 lines (20 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
###############
# Authored by Weisheng Jiang
# Book 7 | From Basic Arithmetic to Machine Learning
# Published and copyrighted by Tsinghua University Press
# Beijing, China, 2022
###############
from scipy.spatial import distance
from sklearn.metrics import pairwise_distances
# Sample data points
X = [[-5, 0], [4, 3], [3, -4]]
# Query point
q = [[0, 0]]
# Compute the Chebyshev distance.
d_1 = distance.chebyshev(q, X[0])
d_2 = distance.chebyshev(q, X[1])
d_3 = distance.chebyshev(q, X[2])
# pairwise distances between rows of X and q
dst_pairwise_X_q = pairwise_distances(X, q, metric='chebyshev')
print('Pairwise Chebyshev distances between X and q')
print(dst_pairwise_X_q)