MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / euclidean_distance_no_np

Function euclidean_distance_no_np

maths/euclidean_distance.py:28–37  ·  view source on GitHub ↗

Calculate the distance between the two endpoints of two vectors without numpy. A vector is defined as a list, tuple, or numpy 1D array. >>> euclidean_distance_no_np((0, 0), (2, 2)) 2.8284271247461903 >>> euclidean_distance_no_np([1, 2, 3, 4], [5, 6, 7, 8]) 8.0

(vector_1: Vector, vector_2: Vector)

Source from the content-addressed store, hash-verified

26
27
28def euclidean_distance_no_np(vector_1: Vector, vector_2: Vector) -> VectorOut:
29 """
30 Calculate the distance between the two endpoints of two vectors without numpy.
31 A vector is defined as a list, tuple, or numpy 1D array.
32 >>> euclidean_distance_no_np((0, 0), (2, 2))
33 2.8284271247461903
34 >>> euclidean_distance_no_np([1, 2, 3, 4], [5, 6, 7, 8])
35 8.0
36 """
37 return sum((v1 - v2) ** 2 for v1, v2 in zip(vector_1, vector_2)) ** (1 / 2)
38
39
40if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected