induwara.lk
induwara.lkAI · Machine learning

Minkowski Distance Calculator

Compute the Minkowski (Lₚ) distance between two numeric vectors of any dimension, for any order p ≥ 1 you choose. See the full per-dimension working and the Manhattan (p=1), Euclidean (p=2), and Chebyshev (p→∞) special cases side by side. Matches scikit-learn and SciPy, nothing uploaded.

By Induwara AshinsanaUpdated Jun 11, 2026
Minkowski distance calculator

Any length ≥ 1. Commas, spaces, or new lines.

Must match the length of Vector A.

Any value ≥ 1, integer or not (e.g. 1, 1.5, 2, 3). sklearn's KNN default is p = 2.

Examples
Minkowski (p = 3)
3.2711
Lₚ · 3-D
Manhattan (L1)
5.0000
p = 1 · Σ |aᵢ − bᵢ|
Euclidean (L2)
3.6056
p = 2 · √Σ (aᵢ − bᵢ)²
Chebyshev (L∞)
3.0000
p → ∞ · max |aᵢ − bᵢ|
Decimals

Cross-check. The direct form (Σ |aᵢ − bᵢ|ᵖ)^(1/p) gives 3.2711; the independent overflow-safe form — factoring out the largest difference before raising to p = 3 — gives 3.2711. They reconcile, as they must.

Step-by-step working

Dimaᵢbᵢ|aᵢ − bᵢ||aᵢ − bᵢ|ᵖ
#11.00004.00003.000027.0000
#22.00000.00002.00008.0000
#33.00003.00000.00000.0000
Sum S = Σ |aᵢ − bᵢ|ᵖ35.0000
dₚ = (|3.0000|^3 + |2.0000|^3 + |0.0000|^3)^(1/3) = 35.0000^(1/3) = 3.2711

Copy-ready SciPy snippet

Python · SciPy
from scipy.spatial.distance import minkowski
minkowski([1, 2, 3], [4, 0, 3], p=3)  # ≈ 3.2711

Paste into Python to reproduce this exact result with SciPy. scikit-learn's DistanceMetric.get_metric("minkowski", p=3) returns the same value.

Method: dₚ = (Σ |aᵢ − bᵢ|ᵖ)^(1/p) — scikit-learn DistanceMetric "minkowski" and SciPy spatial.distance.minkowski. Special cases: p=1 Manhattan, p=2 Euclidean, p→∞ Chebyshev. Nothing leaves this page.

How it works

The Minkowski distance is the generalized Lₚ metric. For two equal-length vectors a = [a₁…aₙ] and b = [b₁…bₙ] and an order p ≥ 1, it is the p-th root of the sum of the p-th powers of the absolute coordinate differences. It is the metric family scikit-learn and SciPy use for nearest-neighbour search, and Manhattan, Euclidean, and Chebyshev distance are all special cases of it.

dₚ(a, b) = ( Σ |aᵢ − bᵢ|ᵖ )^(1/p) = ( |a₁ − b₁|ᵖ + … + |aₙ − bₙ|ᵖ )^(1/p)

The tool computes this in three steps:

  1. Per-dimension absolute difference. Subtract the vectors coordinate by coordinate and take the magnitude: dᵢ = |aᵢ − bᵢ| (the NIST / SciPy definition).
  2. Raise to p and sum. Raise each difference to the power p and add them: S = Σ dᵢᵖ — the inner sum used by scikit-learn's DistanceMetric "minkowski".
  3. Take the p-th root. The distance is dₚ = S^(1/p), matching scipy.spatial.distance.minkowski(a, b, p).

The named metrics are just specific orders of the same sum, and the tool reports all three alongside your chosen p:

  • p = 1 → Manhattan (L1): Σ |aᵢ − bᵢ| — the city-block path.
  • p = 2 → Euclidean (L2): √( Σ (aᵢ − bᵢ)² ) — the straight line.
  • p → ∞ → Chebyshev (L∞): maxᵢ |aᵢ − bᵢ| — the largest single-axis gap.

Chebyshev is computed directly via the maximum rather than by plugging a huge number in for p, because |aᵢ − bᵢ|ᵖ would overflow to infinity for a large finite p. p ≥ 1is enforced because the triangle inequality — and therefore a true metric — fails for 0 < p < 1. All arithmetic is done in double-precision floating point on the raw inputs and is rounded only for display. As a credibility check, the calculator recomputes the distance a second way — an overflow-safe scaled form that factors out the largest difference before raising it to p — and confirms the two routes agree, so even inputs around 10⁹ stay exact.

Worked examples

Integers, p = 3 — a = [1, 2, 3], b = [4, 0, 3]

  1. Absolute differences: |1 − 4| = 3, |2 − 0| = 2, |3 − 3| = 0
  2. Raised to p = 3: 3³ = 27, 2³ = 8, 0³ = 0, sum S = 35
  3. Minkowski: dₚ = 35^(1/3) = 3.2711
  4. Compare: Manhattan = 5, Euclidean = √13 = 3.6056, Chebyshev = 3
  5. scipy.spatial.distance.minkowski([1,2,3],[4,0,3], p=3) = 3.2710663 → agrees

Euclidean sanity, p = 2 — a = [0, 0], b = [3, 4]

  1. Absolute differences: 3, 4
  2. Raised to p = 2: 9, 16, sum S = 25
  3. Minkowski: dₚ = 25^(1/2) = 5.0000 (the 3-4-5 right triangle)
  4. At p = 2 this must equal the Euclidean distance 5 → it does
  5. Compare: Manhattan = 7, Chebyshev = 4

Non-integer order, p = 1.5 — a = [2, 5, 1], b = [2, 1, 1]

  1. Absolute differences: 0, 4, 0
  2. Raised to p = 1.5: 0, 4^1.5 = 8, 0, sum S = 8
  3. Minkowski: dₚ = 8^(1/1.5) = 8^(2/3) = 4.0000
  4. With one non-zero component, dₚ collapses to that component for any p
  5. Confirms correct non-integer-p handling

Frequently asked questions

Sources & references

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.