Euclidean Distance

Compute L2 distance between two vectors.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Enter two vectors of the same length and get the Euclidean (L2) distance, the straight-line distance between them. It works in any number of dimensions, not just 2D or 3D.

How to use

1
Step 1
Enter Vector A and Vector B, comma separated.
2
Step 2
Check they have the same length.
3
Step 3
Press Calculate.

How it works

d(a, b) = √Σ(aᵢ − bᵢ)². Larger values mean the points are further apart. Unlike cosine similarity, Euclidean distance depends on the magnitude of the vectors, so scale features first.

d(a, b) = √( Σ (aᵢ − bᵢ)² )

Worked example

A 3-4-5 triangle

Input
A = 1, 2, 3 B = 4, 6, 3
Output
5
Walkthrough
The differences are 3, 4 and 0, so the distance is √(9 + 16 + 0) = √25 = 5.

Limitations

  • Both vectors must be the same length.
  • Sensitive to scale; normalise features with very different ranges first.

Questions

How do I calculate Euclidean distance?
Square the differences of each pair of components, add them and take the square root. The tool does it for you.
What is the difference between L1 and L2 distance?
L2 is straight-line distance; L1 (Manhattan) is the sum of absolute differences.
Is Euclidean distance good for embeddings?
For normalised embeddings it ranks the same as cosine similarity; otherwise cosine is more common.
Does it work in 100 dimensions?
Yes, any length.

Features

  • Any dimension
  • Instant result
  • Runs in your browser

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • Mean, Variance and Standard Deviation

    StatQuest with Josh Starmer

    Stats foundations behind many ML metrics tools.

    Watch on YouTube
  • TensorFlow 2.0 Complete Course

    freeCodeCamp.org

    Practical ML stack context next to AI utilities.

    Watch on YouTube