import networkx as nx import numpy as np # 读取GML文件 G = nx.read_gml('karate.gml',label='id') #显示矩阵中全部内容 np.set_printoptions(threshold=np.inf) # 获取节点数量 n = G.number_of_nodes() # 初始化一个n*n的零矩阵 matrix = np.zeros((n, n)) # 遍历每一条边 for edge in G.edges(): # 在矩阵中对应的位置设为1 matrix[edge[0]-1][edge[1]-1] = 1 print(matrix)
输入gml文件,输出相对应的0-1矩阵
最新推荐文章于 2024-05-21 23:04:25 发布