def read_graph(filename,g_type):
with open('data/'+filename,'rb') as f:
if g_type == "undirected":
G = nx.read_weighted_edgelist(f)
else:
G = nx.read_weighted_edgelist(f,create_using=nx.DiGraph())
node_idx = G.nodes()
adj_matrix = np.asarray(nx.adjacency_matrix(G, nodelist=None,weight='weight').todense())
return adj_matrix, node_idx
评论列表
文章目录