Thank you so much, Tamas! It is indeed the int vs numpy.int64 issue. I
converted with list(array) instead of array.tolist() and while the latter
converts the elements to int the former doesn't.

Thanks,
Tim


On Fri, Apr 25, 2014 at 5:10 AM, Tamás Nepusz <[email protected]> wrote:

>
> Hi,
>
> > 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__,
> reverse=True)[:10]
>
> > 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,
> Tamas
>
_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to