我使用networkx生成有向图。我想使用greedy_modularity_communities(G, weight=None)在我的图表中找到社区。正如在Networkx文档中提到的,我正在导入以下模块。
from networkx.algorithms import community
from networkx.algorithms.community import greedy_modularity_communities但我发现了一个错误:
ImportError:无法导入名称“greedy_modularity_communities”
发布于 2018-05-21 15:39:43
从链接的URL中可以看到,您正在查看的文档来自“最新”,在页面的左上角,您可以看到这些文档来自的版本是"2.2rc1.dev_20180504030509",这是尚未发布的版本2.2的发布候选版本。
如果需要,可以按照networkx文档中的说明安装开发版本,然后它就可以工作了:
>>> 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和尚未完成的测试。编码器要小心。
发布于 2018-05-21 15:43:38
最新版本的networkx似乎将greedy_modularity_communities移动到了modularity_max模块,如这里所示。
这还没有包含在通过PIP安装的包的版本中,所以如果您需要这个函数,您可能需要尝试最新的dev版本。
https://stackoverflow.com/questions/50451653
复制相似问题