使用 SciPy 计算欧几里得距离

欧氏距离是两个实值向量之间的距离。大多数情况下,我们使用它来计算具有数值(浮点数或整数值)的两行数据之间的距离。 

让我们看看如何使用 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)
euclidean_distance = distance.euclidean(A, B)
print('Euclidean Distance b/w', A, 'and', B, 'is: ', euclidean_distance)
输出结果
Euclidean Distance b/w (1, 2, 3, 4, 5, 6) and (7, 8, 9, 10, 11, 12) is:
14.696938456699069