induwara.lk
induwara.lkAI · Machine learning

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.

By Induwara AshinsanaUpdated Jul 16, 2026
Canberra distance calculator

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

Must have the same number of values as X.

Examples
Canberra distance
1.361905
Σ |xᵢ − yᵢ| / (|xᵢ| + |yᵢ|) · range [0, 3]
Normalized (d ÷ n)
0.453968
Mean per-coordinate term ∈ [0, 1]
Dimensions
3
All coordinate pairs contribute
Decimals
Worked expression
|1.000000 − 4.000000| / (1.000000 + 4.000000) + |2.000000 − 5.000000| / (2.000000 + 5.000000) + |3.000000 − 6.000000| / (3.000000 + 6.000000) = 0.600000 + 0.428571 + 0.333333 = 1.361905

Cross-check. The direct form Σ |xᵢ − yᵢ| / (|xᵢ| + |yᵢ|) gives 1.361905; an independent sign-based form — opposite-sign pairs give 1, same-sign pairs give ||xᵢ| − |yᵢ|| / (|xᵢ| + |yᵢ|), both-zero pairs give 0 — gives 1.361905. They reconcile, as they must.

Step-by-step working

Dimxᵢyᵢ|xᵢ − yᵢ||xᵢ| + |yᵢ|term
#11.0000004.0000003.0000005.0000000.600000
#22.0000005.0000003.0000007.0000000.428571
#33.0000006.0000003.0000009.0000000.333333
Totals1.361905

Method: Canberra d = Σ |xᵢ − yᵢ| / (|xᵢ| + |yᵢ|), a weighted L1 metric — scipy.spatial.distance.canberra canberra. Both-zero coordinates contribute 0 by convention. Each term ∈ [0, 1], so the distance ∈ [0, n]. Nothing leaves this page.

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:

  1. 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].
  2. Zero convention. If a coordinate is zero in both vectors the term is 0/0, which is undefined. Following scipy.spatial.distance.canberra the 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.
  3. 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 value d ÷ 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

Basic, no zeros — x = [1, 2, 3], y = [4, 5, 6]

  1. Term 1: |1 − 4| / (1 + 4) = 3/5 = 0.600000
  2. Term 2: |2 − 5| / (2 + 5) = 3/7 = 0.428571
  3. Term 3: |3 − 6| / (3 + 6) = 3/9 = 0.333333
  4. Canberra: 0.600000 + 0.428571 + 0.333333 = 1.361905
  5. Normalized: 1.361905 / 3 = 0.453968 → canberra([1,2,3],[4,5,6]) = 1.361905 matches

Both-zero coordinate — x = [0, 3, 0], y = [0, 1, 4]

  1. Term 1: |0| + |0| = 0 → 0/0 → 0 (convention)
  2. Term 2: |3 − 1| / (3 + 1) = 2/4 = 0.500000
  3. Term 3: |0 − 4| / (0 + 4) = 4/4 = 1.000000
  4. Canberra: 0 + 0.5 + 1.0 = 1.500000
  5. Normalized: 1.5 / 3 = 0.500000 — the both-zero pair adds nothing

Opposite signs, the per-term maximum — x = [−1, −2], y = [3, 1]

  1. Term 1: |−1 − 3| / (|−1| + |3|) = 4/4 = 1.000000 (opposite signs → 1)
  2. Term 2: |−2 − 1| / (|−2| + |1|) = 3/3 = 1.000000 (opposite signs → 1)
  3. Canberra: 1.0 + 1.0 = 2.000000 = n, the maximum for 2 dimensions
  4. Normalized: 2 / 2 = 1.000000 — every coordinate maximally disagrees

Frequently asked questions

Sources & references

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

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.