1

I have a directed graph-tool graph g. I also have already calculated the pagerank for each vertex in the graph using graph_tool.centrality.pagerank as shown below.

v_pr = g.new_vertex_property('float')
pr = pagerank(u, prop=v_pr)
u.vp['vertex_pagerank'] = v_pr

From here, I can access the pagerank value of a vertex given its index.

What I want to do, however, is to extract, say, the top 10 vertices of the graph in terms of their pagerank values.

Is there a quick way to do this on graph-tool?

EFL
  • 938
  • 4
  • 11
  • 23

1 Answers1

0

I'm new to graph-tool and was wondering about a similar problem. Don't know how efficient my solution is, but for what it's worth I ended up doing it like this:

vertices_by_rank = sorted(u.vertices(), key=lambda v: pr[v], reverse=True)
Rodrigo Vargas
  • 145
  • 1
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 25 '23 at 01:43