Get all edges linked to a given node in a networkx graph

后端 未结 2 826
清酒与你
清酒与你 2021-01-01 10:22

Just wondering if there is convenient networkx function that returns a list of edges connected to a given node (or nodes) (e.g. my_node_name) in a graph (e.g. <

2条回答
  •  清歌不尽
    2021-01-01 11:29

    You can use the method edges on a node for an un-directed graph:

    G.edges(['my_node_name'])
    

    or the function edges

    networkx.edges(G, ['my_node_name'])
    

    But for directed graphs the above method will only give the out-edges; there you need to call and combine both in_edges() and out_edges().

提交回复
热议问题