VertexIndex[g,v]
gives the integer index for the vertex v in the graph g.
VertexIndex[{vw,…},…]
uses rules vw to specify the graph g.
VertexIndex
VertexIndex[g,v]
gives the integer index for the vertex v in the graph g.
VertexIndex[{vw,…},…]
uses rules vw to specify the graph g.
Details
- VertexIndex is also known as vertex ordering.
- VertexIndex is a mapping that assigns a unique integer index to each vertex in a graph, often used for referencing elements in arrays.
- VertexIndex gives the ordering used in functions such as VertexList, AdjacencyMatrix, KirchhoffMatrix, IncidenceMatrix and GraphDistanceMatrix.
- VertexIndex[g,v] gives the position for a vertex v in VertexList[g].
- VertexIndex[g,v] gives the row position for a vertex v in IncidenceMatrix[g].
- VertexIndex[g,v] gives the row and column positions for a vertex v in AdjacencyMatrix[g], KirchhoffMatrix[g] and GraphDistanceMatrix[g].
Examples
open all close allBasic Examples (1)
Scope (4)
VertexIndex works with undirected graphs:
VertexIndex[[image], a]VertexIndex[[image], a]Use rules to specify the graph:
VertexIndex[{a -> b, b -> c, c -> a}, a]VertexIndex works with large graphs:
g = GridGraph[{10, 10, 10, 10, 10}];VertexIndex[g, 1234]//TimingProperties & Relations (11)
The VertexIndex of a vertex corresponds to its position in VertexList:
g = [image];Table[VertexList[g][[VertexIndex[g, v]]] === v, {v, VertexList[g]}]VertexIndex is typically faster than Position:
g = GridGraph[{10, 10, 10, 10}];{Timing[VertexIndex[g, 2]], Timing[Position[VertexList[g], 2]]}VertexQ can be used to tell whether VertexIndex will succeed:
g = [image];{VertexQ[g, 3], VertexIndex[g, 3]}Use EdgeIndex to find the integer index of an edge:
EdgeIndex[CompleteGraph[5], 24]VertexIndex gives the row and column ordering used in AdjacencyMatrix:
g = Graph[{ad, ab, bc, cd}];(m = AdjacencyMatrix[g])//MatrixFormTest whether
and
are adjacent:
m[[VertexIndex[g, a], VertexIndex[g, c]]]VertexIndex gives the row and column ordering used in WeightedAdjacencyMatrix:
g = Graph[{ad, ab, bc, cd}, EdgeWeight -> RandomInteger[{1, 5}, 4]];(m = WeightedAdjacencyMatrix[g])//MatrixFormm[[VertexIndex[g, a], VertexIndex[g, d]]]VertexIndex gives the row and column ordering used in AdjacencyMatrix:
g = Graph[{ad, ab, bc, cd}];(m = GraphDistanceMatrix[g])//MatrixFormFind the shortest distance between
and
:
m[[VertexIndex[g, a], VertexIndex[g, c]]]VertexIndex gives the row and column ordering used in KirchhoffMatrix:
g = Graph[{ad, ab, bc, cd}];(m = KirchhoffMatrix[g])//MatrixFormm[[VertexIndex[g, a], VertexIndex[g, a]]]VertexIndex and EdgeIndex give the row and column ordering used in IncidenceMatrix:
g = Graph[{ad, ab, bc, cd}];(m = IncidenceMatrix[g])//MatrixFormm[[VertexIndex[g, a], EdgeIndex[g, ad]]]VertexIndex gives the ordering of VertexDegree:
g = Graph[{23, 31, 34, 12}];VertexDegree[g][[VertexIndex[g, 1]]]Use VertexDegree directly:
VertexDegree[g, 1]VertexIndex gives the ordering of centralities:
g = Graph[{23, 31, 34, 12}];Find centrality measures for 1:
DegreeCentrality[g][[VertexIndex[g, 1]]]EigenvectorCentrality[g][[VertexIndex[g, 1]]]ClosenessCentrality[g][[VertexIndex[g, 1]]]Possible Issues (1)
Some vertices do not seem to have integer indices:
v = Block[{ϵ = 10 ^ -15}, Range[1.1, 1.4, 0.1] + ϵ]g = Graph[v, Table[v[[i]]v[[i + 1]], {i, 1, 3}], VertexShapeFunction -> "Name"]VertexIndex[g, 1.2]Membership is tested using SameQ rather than Equal:
{v[[2]] === 1.2, v[[2]] == 1.2}By using identical expressions, the integer index is found:
VertexIndex[g, v[[2]]]Related Guides
Text
Wolfram Research (2010), VertexIndex, Wolfram Language function, https://reference.wolfram.com/language/ref/VertexIndex.html (updated 2015).
CMS
Wolfram Language. 2010. "VertexIndex." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/VertexIndex.html.
APA
Wolfram Language. (2010). VertexIndex. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/VertexIndex.html
BibTeX
@misc{reference.wolfram_2026_vertexindex, author="Wolfram Research", title="{VertexIndex}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/VertexIndex.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_vertexindex, organization={Wolfram Research}, title={VertexIndex}, year={2015}, url={https://reference.wolfram.com/language/ref/VertexIndex.html}, note=[Accessed: 13-June-2026]}