通过指定节点列表,可以很容易地从NetworkX图中提取子图,但是我找不到一种有效的方法来执行子图的边提取。例如,提取子图包含的边的权重超过用户定义的阈值。在
目前我的做法是:
## extracts all edges satisfy the weight threshold (my_network is directed):
eligible_edges = [(from_node,to_node,edge_attributes) for from_node,to_node,edge_attributes in my_network.edges(data=True) if edge_attributes['weight'] > threshold]
new_network = NetworkX.DiGraph()
new_network.add_edges_from(eligible_edges)
有更好的方法吗?在
谢谢你的回答。在
这看起来是最好的解决办法。在
您可以使用
graph.edges_iter()
而不是graph.edges()
来节省内存相关问题 更多 >
编程相关推荐