Skip to content
Advertisement

Networkx: Creating a complete graph for a given set of nodes

I have a list as c4_leaves = [56,78,90,112]. I’m trying to create a complete graph using these elements in c4_leaves as nodes. Here’s what I’ve tried:

JavaScript

And then the minimum spanning tree of the above graph as:

JavaScript

When I draw G_ex, it gives me the correct graph, but when I print details of the minimum spanning tree, it shows that T_ex.nodes() = [0,1,2,3,56,78,90,112].

Can someone show me the mistake I’m making?

Advertisement

Answer

It is an old question. However, I am still putting my two cents in it. I was faced with the same issue. I am not sure what exactly was blocking point for the actual question but I will write down what I did.

So, I want to create a complete graph with four nodes (56,78,90, and 112). I have a list. I looked up the definition of complete_graph And here is what I saw

JavaScript

Which means it can take an iterator. In the same spirit, I tried the following code

JavaScript

So, there you have it, a complete graph built out of a list.

I hope that this answers the question.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement