I have been scouring the docs trying to find a function that will return a list vertices from an iGraph graph but can't find one. Does anyone know how to do get a list of vertices from an iGraph graph?
3 Answers
12
votes
The property vs of the igraph.Graph object refers to its VertexSeq object:
g = Graph.Full(3)
vseq = g.vs
print type(vseq)
# <class 'igraph.VertexSeq'>
You can also create one from your graph:
g = Graph.Full(3)
vs = VertexSeq(g)
You can use the property as an iterator:
g = Graph.Full(3)
for v in g.vs:
# do stuff with v (which is an individual vertex)
6
votes
1
votes
If you are looking for names (in case you used names for your vertices), the following code will give you the list of names of all vertices in sequence:
named_vertex_list = g.vs()["name"]
If you are looking for just the indices, then simply creating a range object with vcount will give you the indices
vertex_indices = range(g.vcount())