0

I am trying to create a new directed networkX graph given a directed networkX graph and a node_id as input. What I would like to do is the only keep the connected nodes to the node_id parameter on the subgraph. Some example:

current networkX graph:

node_id | edge_to 
france    spain, germany, italy, belgium
spain     france, portugal
portugal  spain
germany   france, netherlands, belgium 

the function I would like to implement:

new_graph = get_subgraph(graph='graph', node_id='spain')

new graph:

node_id | edge_to 
france    spain, germany, italy, belgium
spain     france, portugal
portugal  spain
Pierre-Alexandre
  • 543
  • 1
  • 10
  • 31
  • You can look at my [previous answer](https://stackoverflow.com/questions/57734399/how-do-i-create-network-graph-from-an-adjacency-matrix-for-specific-nodes-only/57740538#57740538) and run the `neigh` function with depth 2. – warped Apr 25 '22 at 11:15
  • thanks! What is the depth can be 2 or greater? – Pierre-Alexandre Apr 25 '22 at 11:52
  • 1
    depth two would give you everything within a two step distance from the staring point, which is what you were asking for in your question. – warped Apr 25 '22 at 12:00

0 Answers0