Search code examples
pythonnetworkx

How to add an additional edge between nodes that already have edges?


I have a Graph object and between each pair of nodes that already has an edge, I would like to add an additional edge? Is there a way to do this without brute force looping through all the edges?


Solution

  • A simple way to do this is:

    temp = nx.Graph(our_graph)
    new_graph = nx.MultiGraph(temp)
    new_graph.add_edges_from(temp.edges)