import networkx as nx# weighted MultiGraphM = 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 MG = nx.Graph()for u,v,data in M.edges(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})]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)