Adding specific weights to edges through dictionary

I have two dictionaries of nodes with edges like below:

all_nodes_edges = {20101: (20102, 20201), 20102: (20101, 20103), 20103: (20102, 20104)}
nodes_with_weights =  {20101: 20201, 20119: 20219, 20201: (20301, 20101)}

I've created the graph and default weights for all the edges in the graph with the below code:

g = nx.Graph(all_nodes_edges)
nx.set_edge_attributes(g, 1, 'weight')

I'm trying to use the nodes_with_weights dict to create weights of 2 on specific edges. How do I achieve this?. Do I have to loop through the dictionary or can I just use a specific nx function?

Sorry kinda new to graphs.



from Recent Questions - Stack Overflow https://ift.tt/3BYG0Fo
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation