scipy.spatial.distance.cdist(XAXBmetric='euclidean'p=2V=NoneVI=Nonew=None)[source]

Computes distance between each pair of the two collections of inputs.

The following are common calling conventions:

  1. cdist(XA, XB, 'euclidean')

    Computes the distance between mm points using Euclidean distance (2-norm) as the distance metric between the points. The points are arranged as mnn-dimensional row vectors in the matrix X.

>>> a =([1,2],[3,4],[5,6])
>>> a
([1, 2], [3, 4], [5, 6])


>>> b = ([3,4],[7,1])
>>> b
([3, 4], [7, 1])

>>> cdist(a,b)
array([[ 2.82842712, 6.08276253],[ 0. , 5. ],[ 2.82842712, 5.38516481]])

结果数组中第一对第一个值: 【1,2】和 【3,4】的距离;第一对第二个值是【1,2】和【7,1】的距离

posted on 2016-03-10 17:30  qqhfeng16  阅读(1838)  评论(0编辑  收藏  举报