我正在尝试使用 networkx 进行社区分析。
我遇到的错误是模块“networkx.algorithms.community”没有属性“girvan_newman”
。
我的 python 版本是 3.6,networkx 版本是 2.0。
这是我的代码:
import networkx as nx
from networkx.algorithms import community
G = nx.barbell_graph(5, 1)
communities_generator = community.girvan_newman(G)
top_level_communities = next(communities_generator)
next_level_communities = next(communities_generator)
sorted(map(sorted, next_level_communities))
最佳答案
function you're looking for与您所拥有的命名空间略有不同。您需要按如下方式导入它:
from networkx.algorithms.community.centrality import girvan_newman
请注意缺少的命名空间的 centrality
部分。
关于python - 属性错误 : module 'networkx.algorithms.community' has no attribute 'girvan_newman' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47017029/