Linear algebra
Euclidean distance
linalg.euclidean-distanceAlso called euclidean distance, l2 distance, distance, dist
Straight-line distance between two points: the L2 norm of their difference.
Notation
first vector
x ∈ ℝn
second vector
y ∈ ℝn
vector length
Size, at least 1
Result: the distance
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
Given
Result
Given
Result
≈ 2.44948974278
Common mistakes
Returns the squared distance
The final square root is missing.
Fix: Take the square root of the sum of squared differences.
Source
Golub and Van Loan 2013
Golub, Gene H.; Van Loan, Charles F. Matrix Computations. 4th ed. Johns Hopkins University Press, 2013.