简体   繁体   English

igraph:获取带有节点和相应属性的字典

[英]igraph: get dict with nodes and corresponding attribute

I have a large igraph network and want to get some attributes of the vertices in the network.我有一个大型 igraph 网络,想要获取网络中顶点的一些属性。 I have created a directed graph and want to run some algorithms:我创建了一个有向图并想运行一些算法:

G = ig.Graph.from_networkx(g)
obj = ig.Graph.authority_score(G)
print(obj)

When I print the list it just gives me list of the authority scores of the vertices.当我打印列表时,它只会给我顶点的权威分数列表。 However I would like to know which node exactly has each value.但是我想知道哪个节点恰好具有每个值。 Is there anyway to generate a dict that shows the correlation?无论如何要生成一个显示相关性的字典吗? In NetworkX one can do something like this:在 NetworkX 中,可以执行以下操作:

obj = {node: g.degree(node) for node in g}

But igraph says the Graph is not iterable.但是 igraph 说 Graph 是不可迭代的。 Anyone have any ideas?有人有想法么?

You can recover the original networkx node identifiers using您可以使用恢复原始 networkx 节点标识符

nx_ids = G.vs.get_attribute_values('_nx_name')

You can then create your dictionary of node, authority pairs with然后,您可以创建您的节点字典,权限对

authority_dict = dict(zip(nx_ids, obj))

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

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