({{, (RefLink[WeightedAdjacencyMatrix, paclet:ref/WeightedAdjacencyMatrix])[g] 
gives the adjacency matrix of edge weights of the graph g.}, {, (RefLink[WeightedAdjacencyMatrix, paclet:ref/WeightedAdjacencyMatrix])[{v->w,…}]
uses rules v->w to specify the graph g. }})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[WeightedAdjacencyMatrix, paclet:ref/WeightedAdjacencyMatrix]) returns a (RefLink[SparseArray, paclet:ref/SparseArray]) object, which can be converted to an ordinary matrix using (RefLink[Normal, paclet:ref/Normal]).

An entry (Subscript[w, ij]) of the weighted adjacency matrix is the weight of a directed edge from vertex (Subscript[ν, i]) to vertex (Subscript[ν, j]). If there is no edge the weight is taken to be 0.

An edge without explicit (RefLink[EdgeWeight, paclet:ref/EdgeWeight]) specified is taken to have weight 1.

An undirected edge is interpreted as two directed edges with opposite directions and the same weight.

The vertices (Subscript[v, i]) are assumed to be in the order given by (RefLink[VertexList, paclet:ref/VertexList])[g].

The weighted adjacency matrix for a graph will have dimensions n×n, where n is the number of vertices.

OpenersPrimaryExamplesSection(Spacer1)Examples  (11)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

The weighted adjacency matrix of an undirected graph:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeWeight->RandomReal[{1,5},3]]

WeightedAdjacencyMatrix[%]//MatrixForm

The weighted adjacency matrix of a directed graph:

Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},EdgeWeight->RandomReal[{1,5},3]]

WeightedAdjacencyMatrix[%]//MatrixForm

OpenersExampleSection1(Spacer1)Scope  (5)

The weighted adjacency matrix of an undirected graph is symmetric:

Graph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,2\[UndirectedEdge]3,2\[UndirectedEdge]4,3\[UndirectedEdge]4},EdgeWeight->RandomReal[{1,5},5]]

WeightedAdjacencyMatrix[%]//MatrixForm

The weighted adjacency matrix of a directed graph can be unsymmetric:

Graph[{1\[DirectedEdge]2,2\[DirectedEdge]1,3\[DirectedEdge]1,3\[DirectedEdge]2,4\[DirectedEdge]1,4\[DirectedEdge]2},EdgeWeight->RandomReal[{1,5},6]]

WeightedAdjacencyMatrix[%]//MatrixForm

Use rules to specify the graph:

WeightedAdjacencyMatrix[{1->3,2->1}]//MatrixForm

The weighted adjacency matrix of the graph with self-loops has diagonal entries:

Graph[{1\[DirectedEdge]1,1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},EdgeWeight->RandomReal[{1,5},4]]

WeightedAdjacencyMatrix[%]//MatrixForm

(RefLink[WeightedAdjacencyMatrix, paclet:ref/WeightedAdjacencyMatrix]) works with large graphs:

Graph[Table[i->Mod[i^2,10^3],{i,0,10^3-1}]];

Timing[m=WeightedAdjacencyMatrix[%]]

Use (RefLink[MatrixPlot, paclet:ref/MatrixPlot]) to visualize the matrix:

MatrixPlot[m]

OpenersExampleSection3(Spacer1)Properties & Relations  (4)

Rows and columns of the weighted adjacency matrix follow the order given by (RefLink[VertexList, paclet:ref/VertexList]):

g=Graph[{2\[UndirectedEdge]3,3\[UndirectedEdge]1,1\[UndirectedEdge]2,1\[UndirectedEdge]4},EdgeWeight->RandomReal[{1,5},4],VertexShapeFunction->"Name"]

VertexList[g]

TableForm[Normal@WeightedAdjacencyMatrix[g],TableHeadings->{c=Style[#,Blue]&/@%,c}]

Use (RefLink[WeightedAdjacencyGraph, paclet:ref/WeightedAdjacencyGraph]) to construct a graph from a weighted adjacency matrix:

WeightedAdjacencyGraph[{{∞,1,∞},{∞,∞,1},{1,1,∞}}]

WeightedAdjacencyMatrix[%]//Normal

The number of rows or columns is equal to the number of vertices:

g=CompleteGraph[5,EdgeWeight->RandomReal[{1,5},10]]

Dimensions[AdjacencyMatrix[g]]

VertexCount[g]

The main diagonals for a loop-free graph are all zeros:

GridGraph[{2,3},EdgeWeight->RandomReal[{1,5},7]]

Diagonal[AdjacencyMatrix[%]]//Normal

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[WeightedAdjacencyGraph, paclet:ref/WeightedAdjacencyGraph])  ▪  (RefLink[WeightedGraphQ, paclet:ref/WeightedGraphQ])  ▪  (RefLink[EdgeWeightedGraphQ, paclet:ref/EdgeWeightedGraphQ])  ▪  (RefLink[EdgeWeight, paclet:ref/EdgeWeight])  ▪  (RefLink[VertexWeightedGraphQ, paclet:ref/VertexWeightedGraphQ])  ▪  (RefLink[VertexWeight, paclet:ref/VertexWeight])  ▪  (RefLink[AdjacencyMatrix, paclet:ref/AdjacencyMatrix])  ▪  (RefLink[IncidenceMatrix, paclet:ref/IncidenceMatrix])  ▪  (RefLink[KirchhoffMatrix, paclet:ref/KirchhoffMatrix])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Graph Construction & Representation, paclet:guide/GraphConstructionAndRepresentation])}, {▪(RefLinkPlain[Graph Properties, paclet:guide/GraphProperties])}, {▪(RefLinkPlain[Graphs and Matrices, paclet:guide/GraphsAndMatrices])}})}})