我想按節點獲取子圖(紅色區域): 子圖由從輸入節點可到達的所有節點組成。NetworkX DiGraph按節點創建子圖(DiGraph)
像G.subgraph(3)從紅色區域返回一個新的DiGraph。
例如我創建一個有向圖,因爲這:
import networkx as nx
G = nx.DiGraph()
G.add_path([1,2,3,4])
G.add_path([3,'a','b'])
A = nx.to_agraph(G)
A.layout()
A.draw('graph.png')
我看着https://networkx.github.io/documentation/latest/reference/generated/networkx.Graph.subgraph.html並將其轉換爲單向的。我測試了out_egdes,strong/weak_connected_component,但它從未工作過。我也看了How to find subgraphs in a directed graph without converting to undirected graph?和Networkx: extract the connected component containing a given node (directed graph)。
我知道Subgraph在DiGraph中不起作用。
有人可以告訴我如何做到這一點?如果生成的Graph也是一個DiGraph
你澄清你怎麼想生成子圖。這是否是從給定輸入節點可以到達的所有節點? –
是的,這就是我正在尋找。對不起,我沒有澄清這一點。順便說一句很有效 – svenhornberg