联合igraph-python的几个Graph对象,包括属性

时间:2016-04-21 12:02:10

标签: python python-2.7 igraph

我有几个子图,我想联合回一个图,目前我将它们保存在一个字典中:

In [364]: result
Out[364]: 
{0: <igraph.Graph at 0x7f5b0f684de0>,
 1: <igraph.Graph at 0x7f5b0f684af8>,
 2: <igraph.Graph at 0x7f5b0f517050>,
 3: <igraph.Graph at 0x7f5b0f517148>,
 4: <igraph.Graph at 0x7f5b0f517240>}

这些子图中的每一个都具有属性ind

In [367]: result[1].vs['name']
Out[367]: ['633', '634', '971']

In [368]: result[2].vs['name']
Out[368]: ['637']

但是当我尝试将它们组合成一个igraph.Graph对象时,它们似乎松散了ind属性:

G = igraph.Graph()
G+=result[0]
G+=result[1]
G+=result[2]
G.vs["name"]
Traceback (most recent call last):

  File "<ipython-input-370-72297b64297b>", line 1, in <module>
    G.vs["name"]

KeyError: 'Attribute does not exist'

我在这里做错了什么?

这是我想要做的草图:

import igraph
sub1 = igraph.Graph.Full(3)
sub1.vs["name"] = ["1", "2", "3"]
sub2 = igraph.Graph.Full(2)
sub2.vs["name"] = ["4", "5"]
result = [sub1,sub2]
G = igraph.Graph()
G += result[0]
G += result[1]
G.vs["name"]
Traceback (most recent call last):

  File "<ipython-input-15-bc406e721319>", line 1, in <module>
    G.vs["name"]

KeyError: 'Attribute does not exist'

1 个答案:

答案 0 :(得分:1)

你在这里做错了什么;遗憾的是,当图形添加到另一个图形时,Python接口不支持保留顶点属性。您必须单独添加属性:

let secondViewController = segue.destinationViewController as! ContainerViewController
   secondViewController.controllerToLoad = "SecondVC"