Euclidean Distance

The Euclidean distance is the most commonly used geometric distance metric, it returns the distance between two points on a plane.

Mathematically, the Euclidean distance is given as:

$$ d(x, y) = \sqrt { \sum_{i=1}^n (x_i - y_i)^2 } $$

where $x$ and $y$ are vectors.

The expanded form of the equation is for two points in a 2-D vector space is:

$$ d(x, y) = \sqrt { (x_1 - x_2)^2 + (y_1 - y_2)^2 } $$

For example, suppose we have two points:

A = (6.3, 4.1), B = (3.2, 1.7)

The Euclidean distance between the two points is given by:

$$ d(A,B) = \sqrt { (6.3 - 3.2)^2 + (4.1 - 1.7)^2 } $$ $$ d(A,B) = \sqrt { (3.1)^2 + (2.4)^2 }$$ $$ d(A, B) = \sqrt { (9.6) + (5.76) } = \sqrt { 15.369 } = 3.92 $$

Implementation with python code:

import numpy as np

a = np.array([6.3, 4.1])
b = np.array([3.2, 1.7])

d = np.sqrt( np.sum( (a - b)**2 ) )
d
3.920459156782531