我想将断开连接的图划分为块(使用 community_spinglass)。但是,一旦我得到子图并使用 community_spinglass() 原始图中顶点的标签就会丢失。我正在处理 40 多个顶点,因此要追踪它们并不容易。这是我的问题的“玩具示例”:
import igraph
from igraph import Graph
g4_matrix = [ [0,0,-1,0,0,0,0], [0,0,0,0.8,0.2,0,0], [-1,0,0,0,0,0,0], [0,0.8,0,0,1,0,0.1], [0,0.2,0,1,0,-0.3,-.7], [0,0,0,0,-0.3,0,1], [0,0,0,0.1,-0.7,1,0] ]
v_name = ["1", "2", "3", "4", "5", "6", "7"]
g4 = Graph.Weighted_Adjacency(g4_matrix, mode = 'undirected',attr = 'weight' )
igraph.plot(g4,bbox = (300, 300),vertex_label = v_name)
在我获得区块和社区后:
g4_blocks = g4.blocks()
g4_block = g4.vs.select(g4_blocks[1])
Block1 = g4.subgraph(g4_block)
igraph.plot(Block1, bbox = (200, 200), vertex_label = v_name)
但是我们看到顶点按照 v_name 列表的顺序排列,而不是它们之前的标签。此外,当我们获得社区时:
comm = Block1.community_spinglass()
for c in comm:
print c
[2, 3, 4]
[0, 1]
我们得到了子图的索引,但是很难与原始图的索引相关联。
有没有办法获得引用原始图的索引或标签的社区?
提前致谢。