from scipy import spatial
import numpy as np
test_arr = np.array([ [1.2, 2.1, 2.3, 4.5],
[2.6, 6.4, 5.2, 6.2],
[7.2, 6.2, 2.5, 1.7],
[8.2, 7.6, 4.2, 7.3] ])
dist = spatial.distance.pdist(test_arr)
spatial.distance.squareform(dist)
Результат:
array([[0. , 5.63471383, 7.79037868, 9.52365476],
[5.63471383, 0. , 6.98140387, 5.91692488],
[7.79037868, 6.98140387, 0. , 6.1 ],
[9.52365476, 5.91692488, 6.1 , 0. ]])