VertexReplace[g,{v1w1,v2w2,…}]
replaces each vertex vi in the graph g by wi.
VertexReplace[{vw,…},…]
uses rules vw to specify the graph g.
VertexReplace
VertexReplace[g,{v1w1,v2w2,…}]
replaces each vertex vi in the graph g by wi.
VertexReplace[{vw,…},…]
uses rules vw to specify the graph g.
Details and Options
- VertexReplace is also known as vertex substitution.
- VertexReplace effectively uses Replace for each vertex in the VertexList.
- VertexReplace works with undirected graphs, directed graphs, multigraphs, and mixed graphs.
Examples
open all close allBasic Examples (2)
Scope (6)
VertexReplace works with undirected graphs:
VertexReplace[[image], {1 -> "hi", 5 -> "hello"}]VertexReplace[[image], {1 -> "hi"}]VertexReplace[[image], {1 -> "hi"}]VertexReplace[[image], {1 -> "hi"}]Use rules to specify the graph:
VertexReplace[{1 -> 3, 2 -> 1, 3 -> 6, 4 -> 6, 1 -> 5, 5 -> 4, 6 -> 1}, {1 -> "hi"}]VertexReplace works with large graphs:
g = GridGraph[{10, 10, 10, 10}];Timing[h = VertexReplace[g, 1 -> VertexCount[g] + 1];]{VertexCount[h], EdgeCount[h]}Applications (1)
Create a graph that is isomorphic to the original graph:
g = PetersenGraph[4, 1, VertexLabels -> "Name", ImagePadding -> 10];vl = VertexList[g]; n = VertexCount[g];
h = VertexReplace[g, Thread[vl -> RandomSample[vl, n]]];IsomorphicGraphQ[g, h]Find an isomorphism that maps two graphs:
map = First[Normal[FindGraphIsomorphism[g, h]]]Highlight and label two graphs according to the mapping:
a = First /@ map;b = Last /@ map;highlightGraph[g_, v_] := HighlightGraph[g, Table[Style[Labeled[v[[i]], v[[i]]], ColorData["TemperatureMap"][i / VertexCount[g]]], {i, VertexCount[g]}], VertexSize -> Large];{highlightGraph[g, a], highlightGraph[h, b]}Properties & Relations (5)
The graph created by replacing vertices has the same number of vertices as the original graph:
g = [image];VertexCount[g] == VertexCount[VertexReplace[g, 1 -> 10]]The graph created by replacing vertices has the same number of edges as the original graph:
g = [image];EdgeCount[g] == EdgeCount[VertexReplace[g, 1 -> 10]]The graph created by replacing vertices is isomorphic to the original graph:
g = [image];IsomorphicGraphQ[g, VertexReplace[g, 1 -> 10]]IndexGraph can be implemented using VertexReplace:
{VertexReplace[[image], {1 -> 5, 2 -> 6, 3 -> 7, 4 -> 8}], IndexGraph[[image], 5]}The graph created by replacing vertices has the same adjacency matrix as the original graph:
g = RandomGraph[{10, 20}]MatrixPlot[AdjacencyMatrix[#]]& /@ {g, VertexReplace[g, {1 -> "a", 3 -> "b"}]}See Also
Related Guides
Text
Wolfram Research (2010), VertexReplace, Wolfram Language function, https://reference.wolfram.com/language/ref/VertexReplace.html (updated 2015).
CMS
Wolfram Language. 2010. "VertexReplace." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/VertexReplace.html.
APA
Wolfram Language. (2010). VertexReplace. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/VertexReplace.html
BibTeX
@misc{reference.wolfram_2026_vertexreplace, author="Wolfram Research", title="{VertexReplace}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/VertexReplace.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_vertexreplace, organization={Wolfram Research}, title={VertexReplace}, year={2015}, url={https://reference.wolfram.com/language/ref/VertexReplace.html}, note=[Accessed: 13-June-2026]}