Manhattan Distance
Compute L1 distance between two vectors.
About this tool
Enter two vectors and get the Manhattan distance, also called L1 or taxicab distance: the sum of the absolute differences along each dimension, as if you could only travel along grid lines.
How to use
How it works
d₁(a, b) = Σ|aᵢ − bᵢ|. It is less sensitive to a single large difference than Euclidean distance because differences are not squared. It is used in k-NN, clustering and L1 regularisation contexts.
d₁(a, b) = Σ |aᵢ − bᵢ|
Worked example
The same pair as the Euclidean example
- Input
- A = 1, 2, 3 B = 4, 6, 3
- Output
- 7
- Walkthrough
- |1 − 4| + |2 − 6| + |3 − 3| = 3 + 4 + 0 = 7, compared with 5 for Euclidean distance.
Limitations
- Both vectors must be the same length.
- Not scale-invariant; normalise features first.
Questions
What is Manhattan distance?
Manhattan vs Euclidean distance?
Is Manhattan distance the same as L1 norm?
When should I use it?
Features
- L1 distance
- Any dimension
- Runs in your browser
Related resources
Guides and videos from around the web—opens on YouTube or the publisher’s site.
Vectors | Essence of linear algebra
3Blue1Brown
Embeddings and vectors start with linear algebra intuition.
Watch on YouTubeBig-O Notation in 100 Seconds
Fireship
Complexity intuition when estimating training/inference cost.
Watch on YouTube
- Data Index
Math is Fun
Stats primers when reading ML evaluation outputs.
- OpenAI Research
OpenAI
Research notes for people exploring AI tooling trends.