I am attempting to create a random networkx graph with each edge having a random weight (representing length).
At the moment I am using the gnm_random_graph
function from the set of networkx
graph generators:
g=nx.gnm_random_graph(5,5)
However, I am struggling to add the random weights. My attempt is based on answers to this question.
for u,v,w in in g.edges(data=True):
w = np.random.randint(0,10)
I am doing this so I can explore and (hopefully) understand the networkx library.
My question has two parts:
1. What is the best way generate a simple networkx graph for example purposes?
2. What is the best way to add weights to an existing networkx graph?