WeightedAdjacencyMatrix
✖
WeightedAdjacencyMatrix
Details and Options

- WeightedAdjacencyMatrix returns a SparseArray object, which can be converted to an ordinary matrix using Normal.
- An entry wij of the weighted adjacency matrix is the weight of a directed edge from vertex νi to vertex νj. If there is no edge the weight is taken to be 0.
- An edge without explicit 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 vi are assumed to be in the order given by VertexList[g].
- The weighted adjacency matrix for a graph will have dimensions
×
, where
is the number of vertices.
Examples
open allclose allBasic Examples (2)Summary of the most common use cases
The weighted adjacency matrix of an undirected graph:

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-dkm3wv


https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-f5ppu9

The weighted adjacency matrix of a directed graph:

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-4qshb


https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-d62e0h

Scope (5)Survey of the scope of standard use cases
The weighted adjacency matrix of an undirected graph is symmetric:

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-brfunn


https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-fo7txu

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

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-becm22


https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-pcpon

Use rules to specify the graph:

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-bndh30

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

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-cuz87q


https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-jtfkjp

WeightedAdjacencyMatrix works with large graphs:

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-jyefgb

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-fi4a2b

Use MatrixPlot to visualize the matrix:

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-ne4gm8

Properties & Relations (4)Properties of the function, and connections to other functions
Rows and columns of the weighted adjacency matrix follow the order given by VertexList:

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-joylju


https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-cwu88m


https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-i573me

Use WeightedAdjacencyGraph to construct a graph from a weighted adjacency matrix:

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-clncmi


https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-p3vm2

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

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-dxrnuc


https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-gmegrm


https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-b6qsb8

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

https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-jez1rj


https://wolfram.com/xid/0bcn9kefk7cgxj5kdixz2-ddcmod

Wolfram Research (2010), WeightedAdjacencyMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/WeightedAdjacencyMatrix.html (updated 2015).
Text
Wolfram Research (2010), WeightedAdjacencyMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/WeightedAdjacencyMatrix.html (updated 2015).
Wolfram Research (2010), WeightedAdjacencyMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/WeightedAdjacencyMatrix.html (updated 2015).
CMS
Wolfram Language. 2010. "WeightedAdjacencyMatrix." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/WeightedAdjacencyMatrix.html.
Wolfram Language. 2010. "WeightedAdjacencyMatrix." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/WeightedAdjacencyMatrix.html.
APA
Wolfram Language. (2010). WeightedAdjacencyMatrix. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/WeightedAdjacencyMatrix.html
Wolfram Language. (2010). WeightedAdjacencyMatrix. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/WeightedAdjacencyMatrix.html
BibTeX
@misc{reference.wolfram_2025_weightedadjacencymatrix, author="Wolfram Research", title="{WeightedAdjacencyMatrix}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/WeightedAdjacencyMatrix.html}", note=[Accessed: 25-March-2025
]}
BibLaTeX
@online{reference.wolfram_2025_weightedadjacencymatrix, organization={Wolfram Research}, title={WeightedAdjacencyMatrix}, year={2015}, url={https://reference.wolfram.com/language/ref/WeightedAdjacencyMatrix.html}, note=[Accessed: 25-March-2025
]}