简体   繁体   English

在python中更改igraph中的特定节点属性名称

[英]change specific node attribute name in igraph in python

I have an attribute called name in a graph g . 我在图g有一个名为name的属性。 I would like to change the name of one specific node associated with the attribute to a different name. 我想将与该属性关联的一个特定节点的名称更改为另一名称。

For example I have 例如我有

from igraph import *
g = Graph(4)
g.vs['name'] = [(10,1), (269,1331), (3,1), (10,10)]
print g.vs['name']
[(10,1), (269,1331), (3,1), (10,10)]

I would like (3,1) to know be called (4,10) , so the output should be 我想知道(3,1)被称为(4,10) ,所以输出应该是

print g.vs['name']
[(10,1), (269,1331), (4,10), (10,10)]

First, find the index of the node that is currently called (3, 1) : 首先,找到当前称为(3, 1)的节点的索引:

index = g.vs["name"].index((3, 1))

Then, change the name of the node with that index: 然后,使用该索引更改节点的名称:

g.vs[index]["name"] = (4, 10)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM