How can the Euclidean distance be calculated with NumPy?

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

    With Python 3.8, it's very easy.

    https://docs.python.org/3/library/math.html#math.dist

    math.dist(p, q)
    

    Return the Euclidean distance between two points p and q, each given as a sequence (or iterable) of coordinates. The two points must have the same dimension.

    Roughly equivalent to:

    sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))

提交回复
热议问题