Use zip(X, Y)
to get the coordinate pairs, and if you wanna get the euclidian distance between points, it should be (|x1-x2|^2+|y1-y2|^2)^0.5
, not (|x1-y1|^2 - |x2-y2|^2)^1/2
:
In [125]: coords=zip(X, Y)
In [126]: from scipy import spatial
...: dists=spatial.distance.cdist(coords, coords)
In [127]: dists
Out[127]:
array([[ 0. , 0.22248844, 0.09104884, 0.75377329, 0.10685954,
0.41534165, 0.5109039 , 0.15149362, 0.19490308, 0.58971785],
[ 0.22248844, 0. , 0.28973034, 0.9737061 , 0.23197262,
0.62852005, 0.73270705, 0.09751671, 0.39258852, 0.81219719],
[ 0.09104884, 0.28973034, 0. , 0.68642072, 0.19047682,
0.33880688, 0.45038919, 0.23539542, 0.1064197 , 0.53629553],
[ 0.75377329, 0.9737061 , 0.68642072, 0. , 0.79415038,
0.35411306, 0.24770988, 0.90290761, 0.59283795, 0.20443561],
[ 0.10685954, 0.23197262, 0.19047682, 0.79415038, 0. ,
0.47665258, 0.54665574, 0.13560014, 0.28381556, 0.61376196],
[ 0.41534165, 0.62852005, 0.33880688, 0.35411306, 0.47665258,
0. , 0.15477091, 0.56683251, 0.24003205, 0.25201351],
[ 0.5109039 , 0.73270705, 0.45038919, 0.24770988, 0.54665574,
0.15477091, 0. , 0.65808357, 0.36700881, 0.09751671],
[ 0.15149362, 0.09751671, 0.23539542, 0.90290761, 0.13560014,
0.56683251, 0.65808357, 0. , 0.34181257, 0.73270705],
[ 0.19490308, 0.39258852, 0.1064197 , 0.59283795, 0.28381556,
0.24003205, 0.36700881, 0.34181257, 0. , 0.45902146],
[ 0.58971785, 0.81219719, 0.53629553, 0.20443561, 0.61376196,
0.25201351, 0.09751671, 0.73270705, 0.45902146, 0. ]])
To get the upper triangle of this array, use numpy.triu
:
In [128]: np.triu(dists)
Out[128]:
array([[ 0. , 0.22248844, 0.09104884, 0.75377329, 0.10685954,
0.41534165, 0.5109039 , 0.15149362, 0.19490308, 0.58971785],
[ 0. , 0. , 0.28973034, 0.9737061 , 0.23197262,
0.62852005, 0.73270705, 0.09751671, 0.39258852, 0.81219719],
[ 0. , 0. , 0. , 0.68642072, 0.19047682,
0.33880688, 0.45038919, 0.23539542, 0.1064197 , 0.53629553],
[ 0. , 0. , 0. , 0. , 0.79415038,
0.35411306, 0.24770988, 0.90290761, 0.59283795, 0.20443561],
[ 0. , 0. , 0. , 0. , 0. ,
0.47665258, 0.54665574, 0.13560014, 0.28381556, 0.61376196],
[ 0. , 0. , 0. , 0. , 0. ,
0. , 0.15477091, 0.56683251, 0.24003205, 0.25201351],
[ 0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0.65808357, 0.36700881, 0.09751671],
[ 0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0.34181257, 0.73270705],
[ 0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0.45902146],
[ 0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ]])