NumPy: Calculate the Euclidean distance
NumPy: Array Object Exercise-103 with Solution
Write a NumPy program to calculate the Euclidean distance.
From Wikipedia: In mathematics, the Euclidean distance or Euclidean metric is the "ordinary" straight-line distance between two points in Euclidean space. With this distance, Euclidean space becomes a metric space. The associated norm is called the Euclidean norm. Older literature refers to the metric as the Pythagorean metric
from scipy.spatial import distance p1 = (1, 2, 3) p2 = (4, 5, 6) d = distance.euclidean(p1, p2) print("Euclidean distance: ",d)
Euclidean distance: 5.196152422706632
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
>>> m = [x ** 2 for x in range(5)] >>> m [0, 1, 4, 9, 16]
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework