Pass the name to the vertices
parameter of the method. See igraph.GraphBase
In [1]: import igraph as ig
In [2]: g = ig.Graph.Formula('a->b<-c')
In [3]: g.vs['name']
Out[3]: ['a', 'b', 'c']
Here you can see that vertices 0, 1 and 2 are called 'a'
, 'b'
and 'c'
. In most places you can refer to vertices either by index (also called “vertex ID”) or by name.
In [4]: g.indegree() # degrees of all vertices in order
Out[4]: [0, 2, 0]
In [5]: g.indegree(1) # degree of vertex with ID 1
Out[5]: 2
In [6]: g.indegree('b') # we can also refer to it by name instead of ID
Out[6]: 2
In [7]: g.indegree(['b', 'c']) # get the degrees of two vertices
Out[7]: [2, 0]
Keep in mind that using vertex names is slower than using vertex IDs and doesn’t work reliably if you have duplicate names (which you might create accidentally). There are some places where only vertex IDs work, but names don’t.