[Top][All Lists]

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

Re: [igraph] Confusing behavior of vertex sequence

From: Tamás Nepusz
Subject: Re: [igraph] Confusing behavior of vertex sequence
Date: Fri, 25 Apr 2014 14:10:46 +0200


> print list(graph.vs.select(top_indices)) # Why does this not work and return 
> []?  

It looks like the select() method does not play nicely with NumPy data types, 
and top_indices is a NumPy array at this point. You can work around the issue 
by converting it back to a list:

>>> top_indices = top_indices.tolist()

FWIW, if you are using NumPy only to find the top elements in pr_scores, 
there’s no need to do that, this would suffice:

from heapq import nlargest
from operator import itemgetter
top_indices, _ = zip(*nlargest(10, enumerate(pr_scores), key=itemgetter(1)))

If your graph is (relatively) small, you can also rely on sorted(); the above 
solution is better in the sense that it does not do a full sort (it builds a 
heap only and extracts the top 10 elements from the heap). The solution with 
sorted() would be:

top_indices = sorted(range(len(pr_scores)), key=pr_scores.__getitem__, 

> for i in top_indices:  
>     print i, focal_subgraph_directed.vs.select(i) # Why does this throw: 
> invalid vertex filter among positional arguments

The elements of a NumPy array are not ordinary Python integers but NumPy 
datatypes (they are numpy.int64 in your case), and they also do not play nicely 
with igraph yet :( You can cast them to an integer explicitly.

I will try to fix these issues in the next release.

All the best,

reply via email to

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