Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python NetworkX递归子节点_Python_Recursion_Nodes_Networkx - Fatal编程技术网

Python NetworkX递归子节点

Python NetworkX递归子节点,python,recursion,nodes,networkx,Python,Recursion,Nodes,Networkx,使用最新的NetworkX(撰写本文时),检索给定节点的所有(递归)子节点的最有效方法是什么? successivers()函数检索直接子节点,在以前的版本中有。dfs\u preorder\u节点在Joel指出的最新版本中仍然有效。文件是可用的 以下实现了所需的,即感兴趣节点的所有递归子节点: import networkx as nx children = [node for node in nx.dfs_preorder_nodes(network, queryID)]` 有一种后代方

使用最新的NetworkX(撰写本文时),检索给定节点的所有(递归)子节点的最有效方法是什么?

successivers()
函数检索直接子节点,在以前的版本中有。

dfs\u preorder\u节点在Joel指出的最新版本中仍然有效。文件是可用的

以下实现了所需的,即感兴趣节点的所有递归子节点:

import networkx as nx 
children = [node for node in nx.dfs_preorder_nodes(network, queryID)]`

有一种后代方法,它将查找所有子节点,包括每个子节点的子节点:


dfs\u预订单\u节点有什么问题?
?啊,我的糟糕!我只能在以前的版本中找到这个,直到现在。出于某种原因,我认为最新版本有类和基于类的方法。干杯您还可以执行
children=list(nx.dfs…
将生成器转换为列表。
1-2
 \
  3
   \
    4
import networkx as nx

G = nx.DiGraph()
G.add_edge(1, 2)
G.add_edge(1, 3)
G.add_edge(2, 4)
res = nx.descendants(G, 1)
print (res) #{2,3,4}