我正在使用Python3.7.1和networkx2.2。我使用networkx生成有向图,并希望按照以下步骤使用社区计算该图的社区:
import networkx as nx
from networkx.algorithms.community import greedy_modularity_communities
G=nx.DiGraph()
G.add_nodes_from([1,10])
G.add_edges_from([(1,2),(3,4),(5,6),(7,1),(2,10),(3,8),(9,8)])
c = list(greedy_modularity_communities(G))
sorted(c[0])我发现了一个错误:
IndexError:列出超出范围的索引
发布于 2018-12-02 16:45:01
我怀疑你的问题是你的图是有向的。greedy_modularity_communities的文档表明,它希望输入是一个Graph,但是您的输入是一个DiGraph。
如果我做了
H = nx.Graph(G)
c = list(greedy_modularity_communities(H))我没有搞错。我不确定它在H中找到的社区是否是您感兴趣的。
https://stackoverflow.com/questions/53572989
复制相似问题