Manhattan Distance

Compute L1 distance between two vectors.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

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

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ᵢ|. 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?
The sum of the absolute differences of the coordinates, like moving along city blocks.
Manhattan vs Euclidean distance?
Manhattan sums absolute differences; Euclidean takes the square root of summed squares. Manhattan is always at least as large.
Is Manhattan distance the same as L1 norm?
It is the L1 norm of the difference between the vectors.
When should I use it?
When you want less influence from one large outlying difference, or for grid-like movement.

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 YouTube
  • Big-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.