WLJS LogoWLJS Notebook

DistanceMatrix

DistanceMatrix[{u1, u2, ...}] gives the matrix of distances between each pair of elements ui, uj.

DistanceMatrix[{u1, u2, ...}, {v1, v2, ...}] gives the matrix of distances between each ui and vj.

Examples

Distance matrix for points:

DistanceMatrix[{{0, 0}, {1, 0}, {0, 1}}]
(* {{0, 1, 1}, {1, 0, Sqrt[2]}, {1, Sqrt[2], 0}} *)

Between two sets:

DistanceMatrix[{{0, 0}}, {{1, 0}, {0, 1}}]
(* {{1, 1}} *)

Please visit the official Wolfram Language Reference for more details.

On this page