Skip to content
Related Articles

Related Articles

Python – Pairwise distances of n-dimensional space array

Improve Article
Save Article
  • Last Updated : 10 Jan, 2020
Improve Article
Save Article

scipy.stats.pdist(array, axis=0) function calculates the Pairwise distances between observations in n-dimensional space.

Parameters :
array: Input array or object having the elements to calculate the Pairwise distances
axis: Axis along which to be computed. By default axis = 0

Returns : Pairwise distances of the array elements based on the set parameters.

Code #1 : 2D Array




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

Output:

Value of pdist is : [19.33907961]

Code #2 : 3D Array




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))  

Output:

Value of pdist is : [21.11871208 24.91987159 19.33907961  
                    5.38516481  2.82842712  6.40312424]
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!