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.

../../_images/sphx_glr_plot_erdos_renyi_001.png

Out:

node degree clustering
0 5 0.400000
1 2 0.000000
2 5 0.500000
3 6 0.266667
4 3 0.666667
5 2 1.000000
6 5 0.200000
7 4 0.666667
8 3 0.666667
9 5 0.600000
0 9 2 1 3 7
1 6
2 8 7 9 6
3 5 4 8 6 9
4 5 6
5
6 7
7 9
8 9
9

# Author: Aric Hagberg (hagberg@lanl.gov)

#    Copyright (C) 2004-2018 by
#    Aric Hagberg <hagberg@lanl.gov>
#    Dan Schult <dschult@colgate.edu>
#    Pieter Swart <swart@lanl.gov>
#    All rights reserved.
#    BSD license.

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('%s %d %f' % (v, nx.degree(G, v), nx.clustering(G, v)))

# 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.021 seconds)

Gallery generated by Sphinx-Gallery