Skip to content Skip to sidebar Skip to footer

How To Rename A Single Node Of A Networkx Graph?

I wanted to know how I can change a single node name of a node of a digraph. I am new to networkx and could only find answers on how to change all node names. In my case I am itera

Solution 1:

You have nx.relabel_nodes for this. Here's a simple use case:

G = nx.from_edgelist([('a','b'), ('f','g')])

mapping = {'b':'c'}
G = nx.relabel_nodes(G, mapping)

G.edges()
# EdgeView([('a', 'c'), ('f', 'g')])

Post a Comment for "How To Rename A Single Node Of A Networkx Graph?"