简体   繁体   English

Networkx:如何在具有节点属性的图形中使用out_edges()?

[英]Networkx: how use out_edges() in a graph with properties in the nodes?

I use networkx library 我使用networkx库

I need to use the out_edges in a MultiDiGraph graph. 我需要在MultiDiGraph图形中使用out_edges。 When I use it in empty nodes works well: 当我在空节点中使用它时效果很好:

g = nx.MultiDiGraph()
g.add_edges_from([(1,2),(3,4),(1,6)])
g.out_edges(1)   

Out: 出:

[(1, 2), (1, 6)]

But if put attributes in nodes: 但是如果将属性放在节点中:

g[1]["foo"] = "fighter"

It crashes: 它崩溃:

g.out_edges(1)
AttributeError: 'str' object has no attribute 'items'

I was setting the attributes in the wrong way. 我用错误的方式设置了属性。 This is the correct way: g.node[1]["foo"] = "fighter" 这是正确的方法:g.node [1] [“ foo”] =“ fighter”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM