#

Note

This documents the development version of NetworkX. Documentation for the current release can be found here.

#

Erdos Renyi

Create an G{n,m} random graph with n nodes and m edges and report some properties.

This graph is sometimes called the Erdős-Rényi graph but is different from G{n,p} or binomial_graph which is also sometimes called the Erdős-Rényi graph.

plot erdos renyi

Out:

node degree clustering
0 3 1.0
1 4 0.3333333333333333
2 3 0.6666666666666666
3 3 0.6666666666666666
4 6 0.3333333333333333
5 5 0.4
6 6 0.4666666666666667
7 3 0.6666666666666666
8 5 0.3
9 2 0

the adjacency list
0 6 5 4
1 9 5 2 8
2 5 8
3 4 6 7
4 5 9 6 8
5 6
6 7 8
7 8
8
9

import matplotlib.pyplot as plt
from networkx import nx

n = 10  # 10 nodes
m = 20  # 20 edges

G = nx.gnm_random_graph(n, m)

# some properties
print("node degree clustering")
for v in nx.nodes(G):
    print(f"{v} {nx.degree(G, v)} {nx.clustering(G, v)}")

print()
print("the adjacency list")
for line in nx.generate_adjlist(G):
    print(line)

nx.draw(G)
plt.show()

Total running time of the script: ( 0 minutes 0.062 seconds)

Gallery generated by Sphinx-Gallery