首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法导入名称“greedy_modularity_communities”

无法导入名称“greedy_modularity_communities”
EN

Stack Overflow用户
提问于 2018-05-21 15:06:10
回答 2查看 3.2K关注 0票数 1

我使用networkx生成有向图。我想使用greedy_modularity_communities(G, weight=None)在我的图表中找到社区。正如在Networkx文档中提到的,我正在导入以下模块。

代码语言:javascript
复制
from networkx.algorithms import community

from networkx.algorithms.community import greedy_modularity_communities

但我发现了一个错误:

ImportError:无法导入名称“greedy_modularity_communities”

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-05-21 15:39:43

从链接的URL中可以看到,您正在查看的文档来自“最新”,在页面的左上角,您可以看到这些文档来自的版本是"2.2rc1.dev_20180504030509",这是尚未发布的版本2.2的发布候选版本。

如果需要,可以按照networkx文档中的说明安装开发版本,然后它就可以工作了:

代码语言:javascript
复制
>>> import networkx
>>> networkx.__version__
'2.2rc1.dev_20180521153746'
>>> from networkx.algorithms.community import greedy_modularity_communities
>>> print(greedy_modularity_communities.__doc__)
Find communities in graph using Clauset-Newman-Moore greedy modularity
    maximization. This method currently supports the Graph class and does not
    consider edge weights.

    Greedy modularity maximization begins with each node in its own community
    and joins the pair of communities that most increases modularity until no
    such pair exists.
    [...]

但是,像往常一样,您应该意识到使用预先发布版本的软件包的危险:经常会有尚未修复的bug和尚未完成的测试。编码器要小心。

票数 0
EN

Stack Overflow用户

发布于 2018-05-21 15:43:38

最新版本的networkx似乎将greedy_modularity_communities移动到了modularity_max模块,如这里所示。

这还没有包含在通过PIP安装的包的版本中,所以如果您需要这个函数,您可能需要尝试最新的dev版本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50451653

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档