Created
June 13, 2024 02:09
-
-
Save talhaahussain/65fe3193964921228cdf97d1788afac8 to your computer and use it in GitHub Desktop.
euclidean_distance.py -- A Python program for computing the line segment length between two n-dimensional points in Euclidean space, using Cartesian coordinates and the Pythagorean theorem, where each point is represented as a list of n length.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def distance(a: list[int], b: list[int]) -> list[int]: | |
assert len(a) == len(b), "Coordinates must be in same dimension." | |
return math.sqrt(sum([(a[i] - b[i])**2 for i in range(len(a))])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment