Skip to content

WeightedAdjacencyMatrix ​

The vertex-by-vertex matrix of edge weights of a weighted Graph, 0 where no edge exists.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageWeightedAdjacencyMatrix!
WeightedAdjacencyMatrix(g)entry (i,j)(i, j) is the weight of the edge from vertex ii to vertex jj (both directions, for an undirected edge) — 1, AdjacencyMatrix's own default, when gg carries no EdgeWeight at all.
Typed signatures
TypePackageApplies
(value) -> list<list<number>>combinatoricsalways

Domain: Collections

Details
  • gg carries its weights via EdgeWeight -> {w1, w2, …}, one weight per edge in EdgeList order, given as a Graph(edges, EdgeWeight -> {…}) option — see Graph's own note. The Property/PropertyValue per-edge form is not supported.
  • A multi-edge (two edges between the same ordered pair) sums its parallel edges' weights, matching how AdjacencyMatrix sums parallel edges' counts.
  • Returned as a plain matrix (a list of lists) rather than Wolfram's default SparseArray — the same simplification AdjacencyMatrix documents, for the same reason.

Examples

1 more kept as data, checked against the oracles
Basic #

The undirected edge's weight is symmetric; the directed edge's is not

live ↗
InWeightedAdjacencyMatrix(Graph([1,2,3],[UndirectedEdge(1,2),DirectedEdge(2,3)],KeyValuePair⁡(EdgeWeight,[5,7])))\mathrm{WeightedAdjacencyMatrix}(\mathrm{Graph}(\bigl\lbrack1, 2, 3\bigr\rbrack, \bigl\lbrack\mathrm{UndirectedEdge}(1, 2), \mathrm{DirectedEdge}(2, 3)\bigr\rbrack, \operatorname{KeyValuePair}(\mathrm{EdgeWeight}, \bigl\lbrack5, 7\bigr\rbrack)))Out[[0,5,0],[5,0,7],[0,0,0]]\bigl\lbrack\bigl\lbrack0, 5, 0\bigr\rbrack, \bigl\lbrack5, 0, 7\bigr\rbrack, \bigl\lbrack0, 0, 0\bigr\rbrack\bigr\rbrack
About
Examples2
Checked againstWolfram Language 2 differ
CrosswalkWolfram Language

See also: AdjacencyMatrix, Graph, GraphDistance