sklearn.metrics.pairwise_distances

sklearn.metrics.pairwise_distances
sklearn.metrics.pairwise_distances(X, Y=None, metric=‘euclidean’, *, n_jobs=None, force_all_finite=True, **kwds)

案例:

>>>from sklearn.metrics.pairwise import pairwise_distances
>>>a=[[1,3],[2,2]]
>>>pairwise_distances(a,metric="euclidean")
array([[0.        , 1.41421356],
       [1.41421356, 0.        ]])
#结果数组的第一行第二列表示a[1]与a[2]的距离

>>>b=[[1,3],[2,2],[1,1]]
>>>pairwise_distances(b,metric="euclidean")
array([[0.        , 1.41421356, 2.        ],
       [1.41421356, 0.        , 1.41421356],
       [2.        , 1.41421356, 0.        ]])
#结果数组的第一行第三列表示a[1]与a[3]的距离

参考资料
[1] sklearn官网 2022.8
[2] sklearn.metrics.pairwise_distances 2019.10

你可能感兴趣的:(#,sklearn,sklearn,python,人工智能)