Search code examples
pythonpython-3.xgraphnetworkxedges

Using networkx to retrieve all edges in common to certain nodes


Using networkx I want to generate a bipartite subgraph from a generic graph. Given two lists of nodes A and B, I first create the subgraph induced by A + B, then I want to delete all the edges between the nodes of A and then the edges between the nodes of B, leaving unaltered the edges from A to B. I am currently clueless about how to perform the edge deletion.


Solution

  • I solved the task using sets of edges. Given my subgraph sub_G

    sub_G.remove_edges(set(sub_G.edges(A)) ^ set(sub_G.edges(B)))