How can the Euclidean distance be calculated with NumPy?

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

    Starting Python 3.8, the math module directly provides the dist function, which returns the euclidean distance between two points (given as tuples or lists of coordinates):

    from math import dist
    
    dist((1, 2, 6), (-2, 3, 2)) # 5.0990195135927845
    

    And if you're working with lists:

    dist([1, 2, 6], [-2, 3, 2]) # 5.0990195135927845
    

提交回复
热议问题