用python编写一个随机邻接矩阵(100个点),并绘制其图形。

1.设图G=<V,E>,其中V={v1,v2,…,vn},并假定结点已经有了从v1到vn的次序,则n阶方阵A=(aij)n*n成为G的邻接矩阵。其中:在这里插入图片描述
用python编写一个随机邻接矩阵(100个点),并绘制其图形。

import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
from numpy import random

G = nx.Graph()
Matrix = np.array(random.randint((2),size=(100,100)))
#print(Matrix)

for i in range(len(Matrix)):
    for j in range(len(Matrix)):
        G.add_edge(i, j)

nx.draw(G)
plt.show()

在这里插入图片描述
在这里插入图片描述
经过多次实验发现,并不会出现一模一样的图形,也可以理解世界上不会出现两片一模一样的雪花。

猜你喜欢

转载自blog.csdn.net/qq_21201679/article/details/88052065