【发布时间】:2021-05-22 20:55:34
【问题描述】:
我在 networkx 中有两个不同的图,一个图有边的总集合。另一个图是总边的子集。如何从边图的总集合中获取权重并将它们添加到新图中的匹配边?
#total edge collection
G.edges(data = True)
OutEdgeDataView([(1, 2, {'weight': 10}), (2, 3, {'weight': 0}), (2, 5, {'weight': 0}), (2, 6, {'weight': 0}),
(2, 1, {'weight': 0}), (3, 4, {'weight': 10}), (3, 7, {'weight': 0}), (3, 8, {'weight': 0}), (3, 2, {'weight': 0}), (4, 3, {'weight': 0}), (5, 2, {'weight': 0}), (6, 2, {'weight': 0}),
(7, 3, {'weight': 0}), (8, 3, {'weight': 0})])
T = nx.Graph()
T.add_edges_from([(1, 2), (2, 3), (2, 5), (2, 6), (3, 8), (3, 4), (3, 7)])
T.edges(data = True)
EdgeDataView([(1, 2, {}), (2, 3, {}), (2, 5, {}), (2, 6, {}), (3, 8, {}), (3, 4, {}), (3, 7, {})])
我希望 T EdgeDataView 看起来像
EdgeDataView([(1, 2, {'weight':10}), (2, 3, {'weight': 0}), (2, 5, {'weight': 0}), (2, 6, {'weight': 0}),
(3, 8, {'weight': 0}), (3, 4, {'weight': 10}), (3, 7, {'weight': 0})])
任何想法都将不胜感激,
【问题讨论】:
标签: python graph nodes networkx edges