[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Get vertices by labels

From: Tamás Nepusz
Subject: Re: [igraph] Get vertices by labels
Date: Mon, 14 Apr 2014 13:40:43 +0200


> I am trying to do some kind of clustering but am having trouble fetching 
> vertices.
> The cluster lists return the labels of the vertices  

Hmmm, I’m not sure about that; which clustering method are you using? For me it 
works like this:

>>> g = Graph.GRG(100, 0.2)
>>> cl = g.community_fastgreedy().as_clustering()
>>> cl[0]
[0, 1, 7, 8, 9, 11, 13, 19]

This lists the indices of the vertices in cluster zero so there’s no need to 
retrieve the indices from the names. It usually goes the other way round, i.e. 
you use vertex IDs as long as possible and translate them to names when it 
comes to displaying them:

>>> g.vs[cl[0]][“name”]

> whereas g.vs essentially returns a vertexsequence object. I wanted to know if 
> there was some way wherein I could
> return the corresponding vertex with the label given as something.
You can do this:


g.vs.find() finds the first vertex that matches the given search criteria and 
returns the corresponding Vertex object. You can then ask for the index of the 
vertex using its ‘index’ property. However, note that the search takes linear 
time for all vertex attributes *except* ‘name’, which is handled specially, 
since igraph builds an O(1) lookup table for the ‘name’ attribute behind the 

> I want to check the degree of the vertex with label 10 suppose.
You can also do that as follows:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]