def network_layout(matrix, k=30):
nbrs = NearestNeighbors(k, algorithm='brute', metric='cosine').fit(matrix)
G = networkx.from_scipy_sparse_matrix(nbrs.kneighbors_graph(matrix))
node_labels = label_propagation(G, verbose=True)
communities_labelprop = np.array([node_labels[i] for i in range(matrix.shape[0])])
pos = graphviz_layout(G, prog="sfdp")
coords = np.array([pos[i] for i in range(len(pos))])
print(coords.shape)
return coords, communities_labelprop
评论列表
文章目录