1
我对NetworkX documentation的阅读表明这应该起作用,但似乎没有?将NetworkX MultiDiGraph转换为字典或从字典中转换
考虑:
import networkx as nx
g = nx.MultiDiGraph()
g.add_nodes_from([0, 1])
g.add_edge(0,1)
g.add_edge(0,1)
g.edges() # returns [(0, 1), (0, 1)]
d = nx.to_dict_of_dicts(g) # returns {0: {1: {0: {}, 1: {}}}, 1: {}}
g2 = nx.from_dict_of_dicts(d, multigraph_input=True)
# or, equivalently?, g2 = MultiDiGraph(d)
g2.edges() # only returns [(0,1)]
我在这里做一个简单的错误,或者这是一个错误?
对于我的应用程序,我发现了一个更好的选择,它使用networkx.readwrite.json_graph
进行序列化,但我认为我会在这里留下问题以防其他人有用。
非常好!非常感谢:)我会想'multigraph_input = True'会照顾到这一点,错过了'create_using' arg。 – Matthew