7. Analyzing graphs
The structure of G
can be analyzed using various graph-theoretic functions such as:
G = nx.Graph()
G.add_edges_from([(1, 2), (1, 3)])
G.add_node("spam") # adds node "spam"
list(nx.connected_components(G))
sorted(d for n, d in G.degree())
nx.clustering(G)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
Some functions with large output iterate over (node, value) 2-tuples. These are easily stored in a dict
(opens new window) structure if you desire.
sp = dict(nx.all_pairs_shortest_path(G))
sp[3]
1
2
2
See Algorithms (opens new window) for details on graph algorithms supported.
编辑 (opens new window)
上次更新: 2021/02/16, 02:45:37