Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

For example I need to know that "a" is linked to "b" and "d"

like image 348
nikosdi Avatar asked Jan 18 '26 14:01

nikosdi


1 Answers

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.

like image 186
Tamás Avatar answered Jan 20 '26 06:01

Tamás



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!