Python中基于igraph的社区检测

2024-09-28 20:53:34 发布

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

我需要检测网络中的社区。 但是,我不能得到会员资格

# Script
from igraph import *

karate = Graph.Read_Pajek("karate.gml")
karate.simplify()
cl = karate.community_fastgreedy()
print cl.membership # ---> Not work

有人知道如何获得会员吗?在


Tags: fromimport网络readclscriptsimplify社区
1条回答
网友
1楼 · 发布于 2024-09-28 20:53:34

此方法返回一个完整的树状图,因此需要先将其转换为聚类。在

from igraph import *
karate = Nexus.get("karate")
cl = karate.community_fastgreedy()
cl.as_clustering().membership

# [0, 1, 1, 1, 0, 0, 0, 1, 2, 1, 0, 0, 1, 1, 2, 2, 0, 1, 2, 0, 
#  2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]

相关问题 更多 >