Note
Go to the end to download the full example code.
Erdos Renyi#
创建一个具有n个节点和m条边的G{n,m}随机图,并报告一些属性。
这个图有时被称为Erdős-Rényi图,但它与G{n,p}或二项图不同,后者有时也被称为Erdős-Rényi图。

node degree clustering
0 4 0.3333333333333333
1 5 0.3
2 4 0.16666666666666666
3 4 0.5
4 4 0.16666666666666666
5 2 0
6 2 0
7 5 0.3
8 5 0.2
9 5 0.3
the adjacency list
0 8 2 9 1
1 2 4 9 3
2 7 6
3 9 8 7
4 7 6 8
5 8 9
6
7 9 8
8
9
import matplotlib.pyplot as plt
import networkx as nx
n = 10 # 10个节点
m = 20 # 20条边
seed = 20160 # 为可重复性初始化随机数生成器
# 使用种子以确保可重复性
G = nx.gnm_random_graph(n, m, seed=seed)
# 一些属性
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)
pos = nx.spring_layout(G, seed=seed) # 用于可重复布局的种子
nx.draw(G, pos=pos)
plt.show()
Total running time of the script: (0 minutes 0.022 seconds)