-
I'm new to using the "networkx" library. I couldn't find a method to find nodes that are in the range between node "h" and "fd" |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
That looks like a very strange criteria. Maybe I am not understanding. Does the phrase "range between node "h" and "fd" mean some sort of alphabetic "between" or are you talking about something like "lie on a shortest path in the network between"? But in general, if you have a criteria for including the nodes that can be written as an expression or a function, you can filter the list of nodes. Or you can create a subgraph and make a copy of that subgraph so it is it's own graph. node_filter = lambda n : <some expression that returns True/False>
nodes = [n for n in G if node_filter(n)] # list of nodes
SG = G.subgraph(nodes)
SG = G.subgraph(nodes).copy() # this is usually how you want to create a subgraph unless it is a short computation If "between" means "lies on a shortest path between", then the shortest_path function returns the path as a list of nodes along the path: |
Beta Was this translation helpful? Give feedback.
That looks like a very strange criteria. Maybe I am not understanding. Does the phrase "range between node "h" and "fd" mean some sort of alphabetic "between" or are you talking about something like "lie on a shortest path in the network between"?
But in general, if you have a criteria for including the nodes that can be written as an expression or a function, you can filter the list of nodes. Or you can create a subgraph and make a copy of that subgraph so it is it's own graph.