在 graph_tool 中使用 add_edge_list 时如何向边缘添加属性?

How to add properties to edges when using add_edge_list in graph_tool?

我正在尝试使用 add_edge_list 而不是按顺序使用 add_edge 一个接一个地插入边使图形创建更快。

但我找不到如何一次创建这些边并将权重 属性 关联到它们,而不会在创建后循环遍历这些边。

来自文档:

https://graph-tool.skewed.de/static/doc/graph_tool.html#graph_tool.Graph.add_edge_list

If given, eprops specifies edge property maps that will be filled with the remaining values at each row, if there are more than two.

添加示例用法,因为 documentation 中的语法有些不清楚。

# the edges of the graph with corresponding properties
edges = [[x_0, y_0, p_0],
         [x_1, y_1, p_1],
         ...
         [x_n, y_n, p_n]]

# creating an external property
any_property_name = g.new_edge_property("int")

# adding list of all properties 
eprops = [any_property_name]

# add edges and properties to the graph
g.add_edge_list(edges, eprops=eprops)