0
当我尝试使用set_edge_attributes在networkx为整数值分配给新属性为所有edeges(有一个无向networkx摹话):得到错误
nx.set_edge_attributes(G, 'new_attr', 1)
错误显示
AttributeError: 'int' object has no attribute 'items'
If values is not a dictionary, then it is treated as a single attribute value that is then applied to every edge in G.
所以应该OK为图中的每条边设置相同的整数值?或者我不能'创造'一个新的属性,必须使用现有的属性?
更新: 看来,我可以用
G.edge[u][v]['new_attr']
创建和访问的属性。但是有没有一种更简单的方法来一次赋值而不使用循环?我需要使用相同的属性初始值初始化网络。
谢谢!它工作正常。我不知道为什么昨天没有工作。 – Jingjin
顺便说一句,我意识到,在我的其他电脑有Python 2.7.3版本这个错误信息仍然弹出。在这种情况下,我需要先更新我的Python吗? – Jingjin