induwara.lk
induwara.lkAI · Machine learning

Manhattan Distance Calculator

Compute the Manhattan (L1 / taxicab / city-block) distance between two points or two vectors of any dimension, in your browser. See the full per-dimension working, the substituted expression, and the Euclidean and Chebyshev comparisons. Matches scikit-learn and SciPy — no signup, nothing uploaded.

By Induwara AshinsanaUpdated Jun 11, 2026
Manhattan distance calculator
Input mode

Any length ≥ 1 — A and B must match.

Same length as A. Commas, spaces, or new lines.

Examples
Manhattan (L1)
5.0000
Σ |aᵢ − bᵢ| · 3-D
Euclidean (L2)
3.6056
√(Σ (aᵢ − bᵢ)²)
Chebyshev (L∞)
3.0000
max |aᵢ − bᵢ|
Decimals
Worked expression
|1.0000 − 4.0000| + |2.0000 − 0.0000| + |3.0000 − 3.0000| = 3.0000 + 2.0000 + 0.0000 = 5.0000

Cross-check. The direct form Σ |aᵢ − bᵢ| gives 5.0000; the independent general Minkowski p = 1 form (Σ |aᵢ − bᵢ|¹)^(1/1) — how SciPy's minkowski(u, v, 1) computes it — gives 5.0000. They reconcile, as they must.

Step-by-step working

Dimaᵢbᵢaᵢ − bᵢ|aᵢ − bᵢ|(aᵢ − bᵢ)²
#11.00004.0000-3.00003.00009.0000
#22.00000.00002.00002.00004.0000
#33.00003.00000.00000.00000.0000
Totals5.000013.0000

Method: Manhattan d₁ = Σ |aᵢ − bᵢ|; Euclidean d₂ = √(Σ (aᵢ − bᵢ)²); Chebyshev d∞ = maxᵢ |aᵢ − bᵢ| — scikit-learn manhattan_distances and SciPy cityblock. Nothing leaves this page.

How it works

Manhattan distance — also called L1, taxicab, or city-block distance — is the distance between two points measured along axis-aligned moves, the way a taxi travels a rectangular street grid rather than cutting diagonally. For two equal-length vectors a = [a₁…aₙ] and b = [b₁…bₙ], it is the sum of the absolute coordinate differences. It is the metric scikit-learn calls manhattan_distances and SciPy calls cityblock.

d₁(a, b) = Σ |aᵢ − bᵢ| = |a₁ − b₁| + … + |aₙ − bₙ|

The tool computes this in three steps:

  1. Per-dimension difference. Subtract the vectors coordinate by coordinate: dᵢ = aᵢ − bᵢ.
  2. Absolute value and sum. Take |dᵢ| for each dimension and add them. That sum Σ |dᵢ| is the Manhattan distance — no squaring, no square root.
  3. Comparison metrics. Over the same differences the tool also reports Euclidean √(Σ dᵢ²) and Chebyshev max |dᵢ|, the L2 and L∞ members of the same Minkowski family.

All three metrics are special cases of the Minkowski distance dₚ = (Σ |aᵢ − bᵢ|ᵖ)^(1/p): p = 1 gives Manhattan, p = 2 gives Euclidean, and p → ∞ gives Chebyshev. Because Manhattan is the p = 1 case, the calculator uses that general form as an independent cross-check — it recomputes (Σ |dᵢ|¹)^(1/1) and confirms it reconciles with the direct Σ |dᵢ| sum, exactly as SciPy's minkowski(u, v, 1) equals cityblock(u, v). All arithmetic is double-precision and is rounded only for display, using the decimal places you pick, so even inputs around 10⁹ stay exact.

Worked examples

n-D vectors — a = [1, 2, 3], b = [4, 0, 3]

  1. Differences: 1 − 4 = −3, 2 − 0 = 2, 3 − 3 = 0
  2. Absolute values: 3, 2, 0
  3. Manhattan: |−3| + |2| + |0| = 3 + 2 + 0 = 5
  4. Euclidean: √(9 + 4 + 0) = √13 = 3.605551, Chebyshev: max(3, 2, 0) = 3
  5. cityblock([1,2,3], [4,0,3]) = 5.0 → matches

2D points, L1 vs L2 — a = [2, 3], b = [5, 7]

  1. Differences: 2 − 5 = −3, 3 − 7 = −4
  2. Absolute values: 3, 4
  3. Manhattan: |−3| + |−4| = 3 + 4 = 7
  4. Euclidean: √(9 + 16) = √25 = 5, Chebyshev: max(3, 4) = 4
  5. The grid path (7) is longer than the straight line (5)

Binary vectors, Manhattan = Hamming — a = [1, 0, 1, 1], b = [0, 0, 1, 0]

  1. Differences: 1, 0, 0, 1
  2. Absolute values: 1, 0, 0, 1
  3. Manhattan: 1 + 0 + 0 + 1 = 2
  4. Euclidean: √2 = 1.414214, Chebyshev: 1
  5. Equals the Hamming distance (2 differing positions) for 0/1 data

Frequently asked questions

Sources & references

The formulas on this page were last cross-checked against these sources on 2026-06-11. Manhattan distance is a stable mathematical definition, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.