使用 SciPy 计算曼哈顿距离
曼哈顿距离,也称为城市街区距离,计算为两个向量之间的绝对差之和。它主要用于描述统一网格(例如城市街区或棋盘)上的对象的向量。
SciPy为我们提供了一个名为cityblock的函数,它返回两点之间的曼哈顿距离。让我们看看如何使用SciPy库计算两点之间的曼哈顿距离-
示例
# Importing the SciPy library fromscipy.spatialimport distance # Defining the points A = (1, 2, 3, 4, 5, 6) B = (7, 8, 9, 10, 11, 12) print(A, B)输出结果
((1, 2, 3, 4, 5, 6), (7, 8, 9, 10, 11, 12))
示例
# Importing the SciPy library
fromscipy.spatialimport distance
# Defining the points
A = (1, 2, 3, 4, 5, 6)
B = (7, 8, 9, 10, 11, 12)
# Computing the Manhattan distance
manhattan_distance = distance.cityblock(A, B)
print('Manhattan Distance b/w', A, 'and', B, 'is: ', manhattan_distance)输出结果Manhattan Distance b/w (1, 2, 3, 4, 5, 6) and (7, 8, 9, 10, 11, 12) is: 36
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬