from scipy.spatial import distance
p1=[(1,1),(2,2),(3,3)]
p2=[(1,1),(2,2)]
p1=np.array(p1,dtype=np.float64)
p2=np.array(p2,dtype=np.float64)
# get distance matrix
dis_matrix1=distance.cdist(p1, p1, 'euclidean')
dis_matrix2=distance.cdist(p1, p2, 'euclidean')
# print result
print(dis_matrix1)
print(dis_matrix2)
结果如下:
[[0. 1.41421356 2.82842712]
[1.41421356 0. 1.41421356]
[2.82842712 1.41421356 0. ]]
[[0. 1.41421356]
[1.41421356 0. ]
[2.82842712 1.41421356]]