简体   繁体   中英

Access nodes with edges to a certain node of interest in igraph python

I have an igraph graph object called g with some edges. I would like to get all nodes with an edge to a certain node

g = Graph.Tree(10, 2)
print g 

IGRAPH U--- 10 9 --
+ edges:
0--1 0--2 1--3 1--4 2--5 2--6 3--7 3--8 4--9

If I select node 1 , then I should get back a list of the other nodes with edges to node 1 (graph is undirected). The output should look like:

[0, 3, 4]

That is exactly what the neighbors method does.

g.neighbors(1)
Out[12]: [0, 3, 4]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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