我已经拉起了一些代码,我在网络x的1.6.1中玩过。在1.8.1上写入gml
或graphml
时不起作用。当我使用Networkx边缘不能正确添加属性
AttributeError: 'str' object has no attribute 'items'
:
的问题归结为暂时无法写入数据字典内边缘属性,像这样:
BasicGraph = nx.read_graphml("KeggCompleteEng.graphml")
for e,v in BasicGraph.edges_iter():
BasicGraph[e][v]['test'] = 'test'
nx.write_graphml(BasicGraph, "edgeTester.graphml")
导致错误for e,v,data in BasicGraph.edges_iter(data=True):
数据打印出像所以:
{'root_index': -3233, 'label': u'unspecified'}
test
也是新属性在字典之外。
该文件说我应该能够像上面那样做。但是,我想我犯了一个愚蠢的错误,并希望被放回正确的道路上!
编辑:
于是我运行该程序与程序中生成的图表:BasicGraph = nx.complete_graph(100)
,它运行得很好。
然后我用一个来自底图的示例graphml文件运行它:BasicGraph = nx.read_graphml("graphmltest.graphml")
,这也工作。 (我甚至导入和导出Cytoscape来检查这不是问题)
所以显然这是我使用的文件。 Here's一个链接,任何人都可以看到它有什么问题吗?
您可以修改代码以不需要加载该文件? – tacaswell
用'nx.complete_graph()'和另一个graphml文件试了一下,它们都工作正常。查看更新! – Darkstarone