Categories
Python Answers

How to calculate the Euclidean distance with Python NumPy?

Spread the love

Sometimes, we want to calculate the Euclidean distance with Python NumPy.

In this article, we’ll look at how to calculate the Euclidean distance with Python NumPy.

How to calculate the Euclidean distance with Python NumPy?

To calculate the Euclidean distance with Python NumPy, we use the numpy.linalg.norm method.

For instance, we write

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

to call numpy.linalg.norm with a and b where a and b are numpy arrays.

Conclusion

To calculate the Euclidean distance with Python NumPy, we use the numpy.linalg.norm method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *