Set information such as length on the edge of NetworkX

Introduction

In NetworkX, I want to set not only edge connections but also edge weights and special properties.

approach

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

Set information such as length on the edge of NetworkX
Lunch invitation bot on Slack
Slack notification of weather information on OpenWhisk
Acquisition of weather information (DarkSky)
Post images of Papillon regularly on Python + AWS Lambda + Slack
Set information such as length on the edge of NetworkX
How to read original data or external data on the Internet with scikit-learn instead of attached data set such as iris
Get only the Python version (such as 2.7.5) on the CentOS 7 shell
Automation of a research on geographical information such as store network using Python and Web API
Let's automatically extract employee information such as average salary from the XBRL data disclosed on EDINET (5/10)
Change the length of Python csv strings
Investigate the effect of outliers on correlation
Set the environment variable PYTHONPATH on zsh
The importance of Lint as Pythonista thinks
Post the subject of Gmail on twitter
Display the graph of tensorBoard on jupyter
Change the order of PostgreSQL on Heroku
Set the process name of the Python program
[Linux] Difference in time information depending on the clock ID of the clock_gettime () function
Set the color on the poster side so that the color of the Youtube subtitles changes automatically.
Set an upper limit on the number of recursive function iterations in Python
Python C / C ++ Extensions: Pass some of the data as np.array to Python (set stride)