Canberra Distance Calculator
Compute the Canberra distance — a weighted L1 metric that divides each coordinate difference by the sum of the two magnitudes — between two numeric vectors of any length, in your browser. See the full per-coordinate working, the normalized value, and the 0/0 = 0 zero convention. Matches scipy.spatial.distance.canberra — no signup, nothing uploaded.
How it works
Canberra distance is a weighted (relative) version of the Manhattan / L1 distance, introduced by Lance and Williams in 1966 for numerical taxonomy. For two equal-length vectors x = [x₁…xₙ] and y = [y₁…yₙ], it divides each absolute coordinate difference by the sum of the two magnitudes before adding them up. It is the metric SciPy calls canberra.
d(x, y) = Σ |xᵢ − yᵢ| / (|xᵢ| + |yᵢ|)
The tool computes this in three steps:
- Per-coordinate term. For each dimension take the absolute difference
|xᵢ − yᵢ|and divide it by the magnitude sum|xᵢ| + |yᵢ|. Because the numerator can never exceed the denominator, each term lands in[0, 1]. - Zero convention. If a coordinate is zero in both vectors the term is 0/0, which is undefined. Following
scipy.spatial.distance.canberrathe tool sets that term to 0, so a both-zero pair contributes nothing rather than producing NaN. Each such pair is flagged in the working table. - Sum and normalize. Add the terms to get the Canberra distance. Since every term is at most 1, the total lies in
[0, n]. The tool also reports the normalized valued ÷ n, which stays in [0, 1] and lets you compare vectors of different lengths.
The division by |xᵢ| + |yᵢ| is what sets Canberra apart from plain Manhattan distance: it turns each coordinate into a relative difference, giving disproportionate weight to gaps near zero. That is why it suits non-negative data spanning many orders of magnitude — a jump from 1 to 2 registers as a large term (0.333), while 1000 to 1001 barely moves the needle (0.0005). Unlike Mahalanobis distance it uses no covariance, and unlike cosine similarity it is not angle-based. To keep the result trustworthy, the calculator recomputes the distance a second way — through an equivalent sign-based form where opposite-sign pairs contribute 1, same-sign pairs contribute ||xᵢ| − |yᵢ|| / (|xᵢ| + |yᵢ|), and both-zero pairs contribute 0 — and confirms the two routes agree, exactly as they equal scipy.spatial.distance.canberra. All arithmetic is double-precision and rounded only for display.
Worked examples
Frequently asked questions
Sources & references
- SciPy — scipy.spatial.distance.canberra (the canonical implementation and 0/0 = 0 convention this tool matches)
- Lance & Williams (1966), The Computer Journal 9(1): 60–64 — origin of the Canberra metric
- Wikipedia — Canberra distance (definition, range, and zero-handling convention)
The formula on this page was last cross-checked against these sources on 2026-07-16. Canberra 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
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.