MultiGraph.adj#

property MultiGraph.adj#

图形邻接对象,包含每个节点的邻居。

此对象是一个只读的类似dict的结构,具有节点键和相邻的dict值。邻居dict由Edgekey-Data-dict的邻居键入。 G.adj[3][2][0]['color'] = 'blue' 设置边缘的颜色 (3, 2, 0)"blue" .

重复G.adj的行为就像一本词典。有用的习语包括 for nbr, edgesdict in G.adj[n].items():

邻居信息也通过为图下标来提供。

实例

>>> e = [(1, 2), (1, 2), (1, 3), (3, 4)]  # list of edges
>>> G = nx.MultiGraph(e)
>>> G.edges[1, 2, 0]["weight"] = 3
>>> result = set()
>>> for edgekey, data in G[1][2].items():
...     result.add(data.get('weight', 1))
>>> result
{1, 3}

对于有向图, G.adj 保留传出(后续)信息。