How can the Euclidean distance be calculated with NumPy?

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

    Here's some concise code for Euclidean distance in Python given two points represented as lists in Python.

    def distance(v1,v2): 
        return sum([(x-y)**2 for (x,y) in zip(v1,v2)])**(0.5)
    

提交回复
热议问题