Distance matrix
A distance matrix is a square array whose entries represent pairwise distances or dissimilarities between objects, points, or vertices.
Build a Robo-Advisor with Python (From Scratch)
A distance matrix is a square array whose entries represent pairwise dissimilarities between objects.
- How it is used
- Prepares correlated assets for hierarchical clustering in hierarchical risk parity portfolio allocation.
- How deep it goes
- Derives two distance matrices and implements both calculations, then defers cluster formation to later steps.
- Examples
- Uses eight ETF-like tickers and Python calculations of correlations, distances, and pairwise vector norms.
- What you can do after
- Build it from scratch by converting return correlations into clustering-ready distance matrices in Python.
Read how Build a Robo-Advisor with Python (From Scratch) explains distance matrix →
Algorithms Every Programmer Should Know
A distance matrix is a square matrix whose entries represent distances between pairs of vertices or locations.
- How it is used
- Stores direct and progressively improved distances so Floyd–Warshall can compute shortest paths between every pair of vertices.
- How deep it goes
- Defines matrix initialization, traces a route update, and notes in-place storage, without deriving the algorithm formally.
- Examples
- Uses a four-vertex directed graph and updates the distance from vertex 4 to vertex 2 to 4 via vertex 1.
- What you can do after
- Apply Floyd–Warshall to compute all-pairs distances and identify negative-weight cycles from the completed matrix.
Read how Algorithms Every Programmer Should Know explains distance matrix →
Statistics Slam Dunk
A distance matrix is a tabular structure containing pairwise distances or dissimilarities between observations.
- How it is used
- Supports hierarchical clustering by quantifying similarity between observations.
- How deep it goes
- Works through Euclidean calculations, R output, and dendrogram construction.
- Examples
- Uses NBA draft pick numbers and average career win shares, including hand-calculated pairwise distances.
- What you can do after
- Apply it via R's dist() and hclust() functions to produce hierarchical clusters.
Modern C
A distance matrix is a matrix whose entry for a pair of points records the distance from the first point to the second.
- How it is used
- Supports shortest-path reasoning by storing distances between ordered pairs of points in a graph.
- How deep it goes
- Defines the representation and sentinel convention, then asks for shortest-path work without supplying an algorithm.
- Examples
- Uses graph G, ordered points i and j, nodes x and y, and SIZE_MAX for absent direct arcs.
- What you can do after
- Evaluate a graph representation and formulate a shortest-path search between two specified nodes.
Also covered in
- Modern C, Third Edition
- Optimization Algorithms: AI techniques for design, planning, and control problems
What to know first
- ASCIIASCII is a 7-bit character-encoding standard that assigns numeric codes to 128 basic Latin characters, symbols, punctuation marks, digits, and control characters.
- breadth-first searchBreadth-first search is a graph or tree traversal algorithm that explores nodes in nondecreasing order of their distance from a starting node.
- connected componentA connected component is a maximal subgraph in which every pair of vertices is connected by a path.
- edgeAn edge is a connection between two vertices or nodes in a graph or related structure, representing a relationship and optionally carrying direction, labels, or weights.
Related concepts
- correlation matrixproduced by · A correlation matrix is a square matrix whose entries represent pairwise correlation coefficients among a set of variables.
- haversine formulaproduced by · The Haversine formula computes the great-circle distance between two points on a sphere from their latitudes and longitudes.
- objective functionused by · An objective function is a mathematical function that assigns values to candidate solutions or parameter settings, which an optimization procedure seeks to minimize or maximize.
- Euclidean distanceused by · Euclidean distance is the straight-line distance between two points, calculated as the square root of the sum of squared differences between corresponding coordinates.
- dist() functionproduced by · The dist() function in base R computes pairwise distances between observations using a specified distance measure.
- Floyd–Warshallproduced by · Floyd–Warshall is a dynamic programming algorithm for computing shortest-path distances between every pair of vertices in a weighted graph.
Questions about distance matrix
What is distance matrix?
A distance matrix is a square array whose entries represent pairwise distances or dissimilarities between objects, points, or vertices.
Which Manning books explain distance matrix?
Build a Robo-Advisor with Python (From Scratch), Algorithms Every Programmer Should Know, Statistics Slam Dunk and Modern C.
What should I know before learning distance matrix?
Manning books that teach distance matrix usually introduce ASCII, breadth-first search, connected component and edge first.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.



