簡體   English   中英

Networkx:如何在具有節點屬性的圖形中使用out_edges()?

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

我使用networkx庫

我需要在MultiDiGraph圖形中使用out_edges。 當我在空節點中使用它時效果很好:

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

出:

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

但是如果將屬性放在節點中:

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

它崩潰:

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

我用錯誤的方式設置了屬性。 這是正確的方法:g.node [1] [“ foo”] =“ fighter”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM