python - 属性错误 : module 'networkx.algorithms.community' has no attribute 'girvan_newman'

标签 python algorithm networkx

我正在尝试使用 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/

相关文章:

algorithm - 给定一个词,我如何获得所有相差一个字母的词的列表?

python - 在网络中有效识别给定距离内的祖先/后代

javascript - 如何在 python django 中解析包含字典的 javascript 列表

python - 仅运行取决于更改的测试

c++ - 帮助鼠标算法中的对象

graph - 当权重具有积极含义时,我们如何定义介数中心性?

python - 如何收缩 NetworkX 中只有 2 条边的节点?

python - Google Colaboratory - 超出最大调用堆栈大小

Python - 如何从 __init__ 方法中引用类变量或方法?

algorithm - 我怎样才能使这个 if 条件更简单?