NetworkX 2.1获取节点i属性集合方法:
G.node[i],返回值为dict类型。
Netowrkx中获取邻居节点的方法出在 networkx.Graph.neighbors,在早期版本中,可以直接使用G.neighbors(i )来获取i 节点的邻居节点,但是在2.0版本中做出调整,可以直接使用G[i ] 获取节点i 的邻居节点。
Graph.neighbors(n)
Return an iterator over all neighbors of node n.
This is identical to iter(G[n])
Parameters:n (node) – A node in the graphReturns:neighbors – An iterator over all neighbors of node nReturn type:iteratorRaises:NetworkXError – If the node n is not in the graph.
Examples
>>>
>>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> [n for n in G.neighbors(0)]
[1]
Notes
It is usually more convenient (and faster) to access the adjacency dictionary as G[n]:
>>>
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_edge('a', 'b', weight=7)
>>> G['a']
AtlasView({'b': {'weight': 7}})
>>> G = nx.path_graph(4)
>>> [n for n in G[0]]
[1]