How can the Euclidean distance be calculated with NumPy?

后端 未结 22 911
春和景丽
春和景丽 2020-11-22 02:29

I have two points in 3D:

(xa, ya, za)
(xb, yb, zb)

And I want to calculate the distance:

dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (         


        
22条回答
  •  旧巷少年郎
    2020-11-22 02:39

    import numpy as np
    from scipy.spatial import distance
    input_arr = np.array([[0,3,0],[2,0,0],[0,1,3],[0,1,2],[-1,0,1],[1,1,1]]) 
    test_case = np.array([0,0,0])
    dst=[]
    for i in range(0,6):
        temp = distance.euclidean(test_case,input_arr[i])
        dst.append(temp)
    print(dst)
    

提交回复
热议问题