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?
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)
You can also try a much simpler version of the command in python by
G = igraph.Graph.Read("your_inputgraph.txt", format="edgelist", directed=False)
# for reading the graph to igraph
nodes = G.vs.indices
nodes will be the list of all nodes in igraph.
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())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With