📜  Python – n 维空间数组的成对距离

📅  最后修改于: 2022-05-13 01:54:32.182000             🧑  作者: Mango

Python – n 维空间数组的成对距离

scipy.stats.pdist(array, axis=0)函数计算 n 维空间中观测值之间的成对距离。

代码 #1:二维数组

from scipy.spatial.distance import pdist
  
arr1 = pdist([[1, 3, 27], 
             [3, 6, 8]]) 
  
print("Arithmetic Mean is :", arr1) 

输出:

Value of pdist is : [19.33907961]

代码 #2:3D 数组

from scipy.spatial.distance import pdist
   
arr1 = [[1, 3, 27],  
        [3, 4, 6],  
        [7, 6, 3],  
        [3, 6, 8]]  
     
print("Arithmetic Mean is :", pdist(arr1))  

输出:

Value of pdist is : [21.11871208 24.91987159 19.33907961  
                    5.38516481  2.82842712  6.40312424]