Mayleen Cortez
Mayleen Cortez

Reputation: 37

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?

Upvotes: 2

Views: 140

Answers (1)

yut23
yut23

Reputation: 3064

A simple way to do this is:

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

Upvotes: 1

Related Questions