0
我需要將節點標記爲在我正在執行的遍歷中訪問過。所以我做G[node]['visited'] = True
。然而,這個混亂了G.neighbors(node)
,給我'visited'
作爲node
的鄰居!處理這個問題的適當方法是什麼?Networkx將屬性作爲鄰居
實施例:
>>> import networkx as nx
>>> G = nx.Graph()
>>> G.add_edge(0,1)
>>> G[0]['visited'] = True
>>> G.neighbors(0)
['visited', 1]
啊。看起來不錯!然後,如果我想要做邊緣屬性,我會做'G.edge [U] [V] [ '流'] = 50'? –
是的。在這裏你可以使用G.edge [u] [v] ['flow'] = 50'或'G [u] [v] ['flow'] = 50'。 – edo
但後者弄亂了鄰接列表,對吧? –