为什么networkx的girvan-newman算法只返回2个社区?

2024-04-24 09:13:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是networkx库,更具体地说是nextworkx.algorithms.community.centrality中的girvan_newman算法,数据集大约有1200个顶点,每个顶点之间有1-10条边。当我运行下面的代码时,我只看到两个社区

ret = girvan_newman(G)
tuple(sorted(c) for c in next(ret))

我想看到它被进一步分解。然后我试着

import itertools
limited=itertools.takewhile(lambda c: len(c) <= 20, ret)
for communities in limited:
  print(tuple(sorted(c) for c in communities))

但是输出是空的,我不确定我做错了什么

我也不知道如何访问要放入数据框架的社区列表,而不仅仅是打印它们

感谢您的帮助


Tags: 数据innetworkxfor社区sorteditertoolscommunities