python-scipyHow can I calculate the distance between two points using Python and SciPy?
The distance between two points can be calculated using Python and SciPy with the following code:
from scipy.spatial import distance
point1 = (1, 2)
point2 = (4, 6)
dist = distance.euclidean(point1, point2)
print(dist)
This will output 5.0
.
The code uses the following parts:
from scipy.spatial import distance
imports the distance module from SciPy.point1
andpoint2
are tuples containing the coordinates of the two points.distance.euclidean(point1, point2)
calculates the Euclidean distance between the two points.print(dist)
prints the distance to the console.
Helpful links
More of Python Scipy
- How can I check if a certain version of Python is compatible with SciPy?
- How can I use Python Numpy to select elements from an array based on multiple conditions?
- How do I use the scipy ttest_ind function in Python?
- How do I use the NumPy transpose function in Python?
- How do I create a 2D array of zeros using Python and NumPy?
- How do I use Python Numpy to read and write Excel (.xlsx) files?
- How do I use Python and SciPy to write a WAV file?
- How can I use Python and SciPy to generate a uniform distribution?
- How do I use Python and SciPy to create a tutorial PDF?
- How can I use Python and SciPy to perform a Short-Time Fourier Transform?
See more codes...