descendants_at_distance#
- descendants_at_distance(G, source, distance)[源码]#
返回图中与
source
距离为固定distance
的所有节点。- 参数:
- GNetworkX 图
一个图
- source图
G
中的节点 - distance所需节点与
source
的距离
- 返回:
- set()
图
G
中与source
距离为给定distance
的所有后代节点组成的集合
示例
>>> G = nx.path_graph(5) >>> nx.descendants_at_distance(G, 2, 2) {0, 4} >>> H = nx.DiGraph() >>> H.add_edges_from([(0, 1), (0, 2), (1, 3), (1, 4), (2, 5), (2, 6)]) >>> nx.descendants_at_distance(H, 0, 2) {3, 4, 5, 6} >>> nx.descendants_at_distance(H, 5, 0) {5} >>> nx.descendants_at_distance(H, 5, 1) set() ----