liveBook · Manning

Distance matrix

A distance matrix is a square array whose entries represent pairwise distances or dissimilarities between objects, points, or vertices.

How 4 Manning books explain it

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.

Read how Statistics Slam Dunk explains distance matrix →

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.

Read how Modern C explains distance matrix →

Also covered in

What to know first

Related concepts

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.