2014-02-26 69 views
1

我需要在網絡中檢測社區。 但是,我不能讓會員使用Python中的igraph進行社區檢測

# Script 
from igraph import * 

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

任何人都知道如何讓會員?

回答

4

此方法返回完整樹狀圖,因此您需要先將其轉換爲羣集。

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] 
相關問題