Euclidean distance equation and calculation

Euclidean distance is calculated as the square root of the sum of the squared difference between corresponding components in two vectors (\(A\) and \(B\)). In summation notation this can be written as:

\[d_{AB} = \sqrt{\sum_{i=1}^{n}(A_i - B_i)^2} \]

Note the similarity between Euclidean distance and the L2 norm (used in the denominator of cosine similarity), where the L2 norm is the simply the Euclidean distance from the origin (0,0), also known as the zero vector (\(0\)). For example, the L2 norm for vector \(A\) is

\[||A||_2 = ||A - 0||_2 = \sqrt{\sum_{i=1}^{n}(A_i - 0)^2} =\sqrt{\sum_{i=1}^{n}A_i^2}\] or simply the square root of the sum of the squared components in vector \(A\).

Suppose we have two vectors, where \(v_1 = [0.10, 0.20]\) and \(v_2 = [0.30, 0.40]\). The Euclidean distance between vectors \(v_1\) and \(v_2\) is:

\[d_{v_1v_2} = \sqrt{\sum_{i=1}^{n}(v_{1i} - v_{2i})^2} = \sqrt{(0.10 - 0.30)^2 + (0.20 - 0.40)^2} = 0.28\].