0
有關於通過使用Maehler的代碼NetworkX轉換多重圖以簡單圖表通過平均平行長度
import networkx as nx
G = nx.MultiGraph()
G.add_nodes_from([1,2,3])
G.add_edges_from([(1, 2), (1, 2), (1, 3), (2, 3), (2, 3)])
G2 = nx.Graph(G)
和另一個使用Aslak和ARIC的代碼求和重量
import networkx as nx
# weighted MultiGraph
M = nx.MultiGraph()
M.add_edge(1,2,weight=7)
M.add_edge(1,2,weight=19)
M.add_edge(2,3,weight=42)
# create weighted graph from M
G = nx.Graph()
for u,v,data in M.edges_iter(data=True):
w = data['weight'] if 'weight' in data else 1.0
if G.has_edge(u,v):
G[u][v]['weight'] += w
else:
G.add_edge(u, v, weight=w)
print G.edges(data=True)
# [(1, 2, {'weight': 26}), (2, 3, {'weight': 42})]
多重圖轉換爲簡單圖的一個解決方案
想知道如何平均平行邊緣的重量?