2

I am using graph-tool to calculate some centrality measures.

from graph_tool.all import *
graph = Graph(directed=True)

Before I do that, I need to initialize the edge properties. I am doing the following:

weight = graph.new_edge_property('double')
graph.edge_properties['weight'] = weight

Adding the edges (from a dataframe). The dataframe has also a column weight.

edges = df[['source', 'target']].values
graph.add_edge_list(edges, hashed=True, eprops=[weight])

I want to initialize the edge properties using a more efficient way than this (I want to avoid the loop):

weight = df[['weight']].values
for edge  in graph.get_edges():
   graph.edge_properties["weight"][edge] = weight[graph.edge_index[edge]]

Can you please suggest a more efficient way to initialize the edge properties? The graph is built from a very large dataframe (30 million rows).

alejo
  • 127
  • 2
  • 11

0 Answers0