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.
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:
- Per-dimension absolute difference. Subtract the vectors coordinate by coordinate and take the magnitude:
dᵢ = |aᵢ − bᵢ|(the NIST / SciPy definition). - Raise to p and sum. Raise each difference to the power p and add them:
S = Σ dᵢᵖ— the inner sum used by scikit-learn'sDistanceMetric "minkowski". - Take the p-th root. The distance is
dₚ = S^(1/p), matchingscipy.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
Frequently asked questions
Sources & references
- scikit-learn — sklearn.metrics.DistanceMetric, "minkowski" (definition d(x,y) = (Σ |xᵢ − yᵢ|ᵖ)^(1/p); default KNN metric at p=2)
- SciPy — scipy.spatial.distance.minkowski (reference implementation and the p ≥ 1 validity constraint; the cross-check oracle)
- NIST Dictionary of Algorithms and Data Structures — Lₘ distance / Minkowski metric and its limiting cases (Manhattan, Euclidean, Chebyshev)
The formulas on this page were last cross-checked against these sources on 2026-06-11. Minkowski distance is a stable mathematical definition, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled against SciPy.
Related tools
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.