Calculate Euclidean Distance within points in numpy array

后端 未结 2 1150
無奈伤痛
無奈伤痛 2021-01-14 01:46

I have 3D array as

 A = [[x1 y1 z1]
      [x2 y2 z2]
      [x3 y3 z3]]

I have to find euclidean distance between each points so that I\'ll

2条回答
  •  长情又很酷
    2021-01-14 02:12

    Consider using scipy.spatial.distance.pdist.

    You can do like this.

    >>> A = np.array([[1, 2, 3], [4, 5, 6], [10, 20, 30]])
    >>> scipy.spatial.distance.pdist(A)
    array([  5.19615242,  33.67491648,  28.93095228])
    

    But be careful the order of the output distance is (row0,row1),(row0,row2) and (row1,row2).

提交回复
热议问题