Nathan Fellman Nathan Fellman - 5 months ago 7
Python Question

How can the euclidean distance be calculated with numpy?

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 + (za-zb)^2)

What's the best way to do this with Numpy, or with Python in general? I have:

a = numpy.array((xa ,ya, za))
b = numpy.array((xb, yb, zb))


Use numpy.linalg.norm:

dist = numpy.linalg.norm(a-b)