开发者

Is there any function that returns the out edges of a node?

开发者 https://www.devze.com 2022-12-19 05:03 出处:网络
I am using python with networkx package. I need to find the nodes connected to out edges of 开发者_运维百科a given node.

I am using python with networkx package. I need to find the nodes connected to out edges of 开发者_运维百科a given node. I know there is a function networkx.DiGraph.out_edges but it returns out edges for the entire graph.


I'm not a networkx expert, but have you tried networkx.DiGraph.out_edges, specifying the source node?

DiGraph.out_edges(nbunch=None, data=False)

Return a list of edges.

Edges are returned as tuples with optional data in the order (node, neighbor, data).

If you just want the out edges for a single node, pass that node in inside the nbunch:

graph.out_edges([my_node])


The simplest way is to use the successors() method:

In [1]: import networkx as nx

In [2]: G=nx.DiGraph([(0,1),(1,2)])

In [3]: G.edges()
Out[3]: [(0, 1), (1, 2)]

In [4]: G.successors(1)
Out[4]: [2]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号