Reputation: 91
I want to compare the performance of two graphs, the second one being a Kn complete graph. Let's call G the first graph (the non-complete one) and H the second one (the Kn graph). I want the nodes from H to have the exact same attributes (and relative values) as the ones from G, so (apparently) I can't just run networkx.complete_graph(n)
. My first idea was to use this code:
H = G.copy()
nh = H.nodes()
eh = H.edges() # I create those variables in hope to save some speed
for u in nh:
for v in filter(lambda x: x > u, nh): # it's an undirected graph, saves some speed
if (u,v) not in eh:
H.add_edge(u,v)
However, since my graphs have 10,000+ nodes, this becomes quite a slow process. Is there a way to speed it up?
Upvotes: 1
Views: 707
Reputation: 91
Ok, I may have found an answer:
H = networkx.complete_graph(n)
labels = nx.get_node_attributes(G,attribute)
nx.set_node_attributes(H,attribute,labels)
Does anyone have a faster alternative?
Upvotes: 1