How can the Euclidean distance be calculated with NumPy?

后端 未结 22 905
春和景丽
春和景丽 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:41

    import numpy as np
    # any two python array as two points
    a = [0, 0]
    b = [3, 4]
    

    You first change list to numpy array and do like this: print(np.linalg.norm(np.array(a) - np.array(b))). Second method directly from python list as: print(np.linalg.norm(np.subtract(a,b)))

提交回复
热议问题