Skip to content

Distance Matrix

An indexed square array whose entry records a declared pairwise distance or dissimilarity, with metric properties present only when the underlying function satisfies them.

Version
v1 · 2026-09-28 · History
Domain-specific #
9016
Domain group
Formal Sciences
Origin domain
Mathematics
Subdomains
Discrete Mathematics, Metric Geometry → Mathematics
Aliases
Pairwise distance matrix, Dissimilarity matrix

Core Idea

For items x1,…,xn, a distance matrix stores D_ij=d(x_i,x_j). Index order and the distance rule are part of its identity. If d is a metric, the diagonal is zero, entries are nonnegative, the matrix is symmetric, and triangle inequalities hold.

Many useful matrices are nonmetric. Directed shortest-path costs can be asymmetric; disconnected pairs may be infinite; negative cycles can make unbounded path distance undefined. Algorithms must therefore consume the properties actually established, not those suggested by the word distance.

How would you explain it like I'm…

The How-Far Table

Some maps have a chart with town names along the top and down the side, and each box tells how far apart two towns are. That chart is a distance matrix. You have to know which towns are in which rows and how 'how far' was measured, or the numbers won't make sense.

Table of Pairwise Distances

A distance matrix is a table that lists a set of things along the top and down the side, and in each box gives the distance between the two things. The order of the things and the rule used to measure distance are part of what the table means. For ordinary distances, the boxes going diagonally are zero, since everything is zero away from itself, no distance is negative, and the table is the same flipped across its diagonal. But not every distance table works that way: with one-way roads, going from A to B might cost more than going from B to A. So you have to check what's true about your table before using it.

Pairwise Distance Array

For items x1 through xn, a distance matrix D has entries D_ij = d(x_i, x_j), the distance from item i to item j. The ordering of items and the distance rule d are part of the matrix's identity. If d is a metric, then the diagonal is zero, all entries are nonnegative, the matrix is symmetric, and every triple of items satisfies the triangle inequality. Many useful distance matrices are not metric, though. Shortest-path costs in a directed network can be asymmetric, pairs that can't reach each other may have infinite distance, and negative cycles can make path distance undefined. Algorithms should rely only on the properties that have actually been established, not on what the word 'distance' suggests.

 

A distance matrix for items x_1, ..., x_n is the n-by-n array D with D_ij = d(x_i, x_j). Its identity includes both the index order and the distance rule d, so reordering items or changing d yields a different object. If d is a metric, D has a zero diagonal, nonnegative entries, symmetry, and satisfies all triangle inequalities D_ik <= D_ij + D_jk. Many practically useful distance matrices are nonmetric, however. Directed shortest-path costs can be asymmetric, disconnected pairs may have infinite entries, and negative cycles can make unbounded path distance undefined. Consequently, algorithms that consume distance matrices, such as clustering, embedding, or shortest-path methods, must use only the properties actually established for the given matrix rather than assuming metric structure because of the word distance.

Scope of Application

  • Graph algorithms. All-pairs shortest paths populate vertex distances.
  • Clustering. Pairwise dissimilarities drive linkage and embedding methods.
  • Phylogenetics. Evolutionary distances summarize pairwise divergence.
  • Spatial analysis. Coordinates induce geometric metric matrices.

Clarity

Report item order, units, direction, formula, preprocessing, unreachable values, and verified axioms. A heat map without those declarations can be visually compelling but semantically ambiguous. This distinction is operationally important. Inclusion test: Declare items, indexing, distance rule, direction, units, missing/unreachable convention, and whether metric axioms are asserted. Exclusion test: Exclude covariance matrices, adjacency matrices, similarities treated as distances without transformation, and mixed-scale entries. Nearest boundary: An adjacency matrix records direct links; a graph distance matrix records shortest-path distance, often including indirect routes. Exit condition: It ceases to represent the claimed distance when indices or rules vary across entries.

Manages Complexity

The matrix makes every pair query immediate and supports linear or tropical algebra, at quadratic storage cost. It compresses raw objects but discards why each distance arose.

Abstract Reasoning

  1. Fix item identities and order.
  2. Define one pairwise rule and units.
  3. Compute every ordered pair consistently.
  4. Test symmetry, diagonal, positivity, and triangle inequality before using metric algorithms.
  5. Represent unreachable or undefined values explicitly.

Knowledge Transfer

Distance matrices transfer across domains when pairwise meaning and required axioms are stated. Similar-looking square arrays do not inherit the identity.

Relationships to Other Abstractions

Local relationship map for Distance MatrixParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Distance MatrixDOMAINDomain-specific abstraction: Matrix — is a kind ofMatrixDOMAIN

Current abstraction Distance Matrix Domain-specific

Parents (1) — more general patterns this builds on

  • Distance Matrix is a kind of Matrix Domain-specific

    A Distance Matrix is a Matrix whose indexed entries record pairwise distances or dissimilarities among the same declared objects.

Hierarchy paths (5) — routes to 5 parentless roots

Neighborhood in Abstraction Space

Distance Matrix sits in a crowded region of the domain-specific corpus (25th percentile for distinctiveness): several abstractions share nearly its structure, so a description that fits it tends to fit its neighbors too.

Family — Matrices, Measures & Numeric Structures (30 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-10-08