In NetworkX, I want to set not only edge connections but also edge weights and special properties.
import networkx as nx
import random
#Properly generated
G = nx.random_tree(10)
#Extract the edge set of G
for (u, v) in G.edges():
G.edges[(u, v)]['weight'] = random.randint(3, 10)
Each side (u, v) (tuple) of NetworkX is
G.edges[(u, v)]
You can take it out with. In other words, it is a dictionary with tuples as keys.
Because this area G.edges [(u, v)] is a dictionary
You can use weight
as a key and put the weight there.
Other
You can add love
, long
, etc. if you want.
Recommended Posts