Statistical Methods

Recover Pair Labels from a Condensed Distance Vector

Define the task

Some routines store only the upper triangle of a symmetric distance matrix. This condensed vector has n(n−1)/2 entries and omits the diagonal. An unlabeled vector can be misinterpreted even when every number is correct. Preserve the ordered object labels from the calculation that produced it. The accompanying tool accepts finite nonnegative entries and reconstructs a symmetric matrix with a zero diagonal; it does not decide whether the distances are scientifically appropriate.

Carry out the check

For zero-based indices, list pairs in row order: (0,1), (0,2), continuing through (0,n−1), then (1,2), and so on. Check that the vector length corresponds to an integer n; an arbitrary number of entries cannot be reshaped into a complete condensed matrix. Do not include diagonal values or the lower triangle. Symmetry and a zero diagonal are structural checks, not proof of the triangle inequality or Euclidean geometry. Record the metric, units and scaling separately before passing distances to a clustering algorithm.

Worked hypothetical example

For fictional objects A,B,C, the vector (2,5,4) means AB=2, AC=5 and BC=4. Its square matrix has rows (0,2,5), (2,0,4), (5,4,0). A four-entry vector cannot describe a complete set of pairwise distances for an integer number of objects. Reordering labels to C,A,B without reordering distances would silently change the scientific meaning. Keep an index-to-label mapping next to the exported matrix and check one known pair manually.

Method checked 16 November 2026 against SciPy documentation: squareform.

Open the condensed distance label decoder.

Related reading

Reading path: Analyze data. Guide 157 of 162. Choose any guide to suit your project.

Statistical Methods

Choose a distance metric with a documented unit convention

Compare distance metrics on measurements with explicit units. Includes a worked matrix example and reproducibility checks.

Statistical Methods

Verify an eigenpair without requiring a fixed vector sign

Check an eigenpair and understand its arbitrary sign.

Browse this reading pathTools for this stageGuides and downloads for this stage