I found DiGraph.reverse()
to reverse the direction of all edges in the directed graph, but is there a way to change the direction of a specific edge only?
It can certainly be done manually, but there's nothing in the API for it.
$ cat edges.py; echo; python edges.py
import networkx as nx
G=nx.DiGraph()
G.add_edge(1,2,{'weight':.5})
G.add_edge(3,4,{'weight':1.0})
attrs = G[1][2]
G.remove_edge(1,2)
G.add_edge(2,1,attrs)
print G.edges(data=True)
[(2, 1, {'weight': 0.5}), (3, 4, {'weight': 1.0})]
$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With