|
From: | Tim Althoff |
Subject: | Re: [igraph] Confusing behavior of vertex sequence |
Date: | Fri, 25 Apr 2014 11:29:04 -0700 |
Hi,
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:
> print list(graph.vs.select(top_indices)) # Why does this not work and return []?
>>> 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__, reverse=True)[:10]
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.
> for i in top_indices:
> print i, focal_subgraph_directed.vs.select(i) # Why does this throw: invalid vertex filter among positional arguments
I will try to fix these issues in the next release.
All the best,
Tamas
[Prev in Thread] | Current Thread | [Next in Thread] |