How can the Euclidean distance be calculated with NumPy?

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

    You can easily use the formula

    distance = np.sqrt(np.sum(np.square(a-b)))
    

    which does actually nothing more than using Pythagoras' theorem to calculate the distance, by adding the squares of Δx, Δy and Δz and rooting the result.

提交回复
热议问题