鄂尔多斯仁义

创建一个具有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 3 0.666667
1 3 0.666667
2 4 0.666667
3 3 0.666667
4 7 0.285714
5 3 0.666667
6 4 0.333333
7 2 0.000000
8 8 0.357143
9 3 1.000000
0 8 1 3
1 4 8
2 9 8 4 6
3 4 8
4 7 8 9 5
5 6 8
6 8 7
7
8 9
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.121 seconds)

Gallery generated by Sphinx-Gallery