鄂尔多斯仁义

创建一个具有n个节点和m个边的g n,m随机图,并报告一些属性。

这个图有时被称为erd_s-r_nyi图,但不同于g_n、p或二项式图,后者有时也被称为erd_s-r_nyi图。

../../_images/sphx_glr_plot_erdos_renyi_001.png

出:

node degree clustering
0 1 0.000000
1 4 0.500000
2 4 0.833333
3 3 0.666667
4 7 0.285714
5 2 1.000000
6 4 0.833333
7 6 0.466667
8 3 0.666667
9 6 0.333333
0 4
1 8 9 3 4
2 9 4 6 7
3 9 4
4 6 7 8
5 9 7
6 9 7
7 8 9
8
9

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

#    Copyright (C) 2004-2019 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.198 seconds)

Gallery generated by Sphinx-Gallery