我正在尝试使用networkx进行社区分析。
我得到的错误是module 'networkx.algorithms.community' has no attribute '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))发布于 2017-10-30 22:24:14
function you're looking for位于与您已有的名称空间略有不同的名称空间中。您需要按如下方式导入它:
from networkx.algorithms.community.centrality import girvan_newman注意名称空间中缺少的centrality部分。
发布于 2019-01-14 17:43:47
升级您的网络x:
pip install --upgrade networkx发布于 2019-10-03 01:36:34
这对我很有效
from networkx.algorithms.community.centrality import girvan_newman
communities_generator = community.centrality.girvan_newman(G)编辑:通过导入community.centrality.girvan_newman(G)而不是community.girvan_newman(G)是这里的关键
https://stackoverflow.com/questions/47017029
复制相似问题