IGraph python从Vertex获取邻居Vetrices [英] IGraph python get neighbour Vetrices from Vertex
问题描述
我有一个图,我想实施页面排名算法的修改。我被困在以下几点。我不知道如何从节点获取所有相邻顶点。
I have a graph and I want to implement a modification of the Page Rank algorithm. I am stuck on the following point. I don't know how to get all the neighboring vertices from a node.
目前,我正在使用以下方式接收边缘列表:
Currently I am receiving the list of the edges using:
g.incident("a", mode="out")
这会返回边缘索引列表。
This returns me the list of the edges indexes.
如何从中获取顶点名称?
How can I get the vertex name from that?
例如,我需要知道a链接到b和d
For example I need to know that "a" is linked to "b" and "d"
推荐答案
g.neighbors(a,mode =out)
会为您提供邻居的顶点索引。然后你可以得到如下名称:
g.neighbors("a", mode="out")
will give you the vertex indices for the neighbors. You can then get the names as follows:
>>> neis = g.neighbors("a", mode="out")
>>> g.vs[neis]["name"]
但实际上,如果我是你,我会尝试尽可能地使用顶点索引,因为与索引相比,使用索引要快得多。
But actually, if I were you, I would try to work with vertex indices as much as possible because it's way faster to work with the indices than with the names.
这篇关于IGraph python从Vertex获取邻居Vetrices的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!