How can the Euclidean distance be calculated with NumPy?

Python

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))

 


If you want to unleash your potential in this competitive field, please visit the Python course page for more information, where you can find the Python tutorials and Python frequently asked interview questions and answers as well.

1
Answers

Replies


You can calculate the Euclidean distance using the numpy.linalg.norm. Use the below line of code.



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


 

 
 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.
WhatsApp
To Top