Petr Petrov
Petr Petrov

Reputation: 4452

NetworkX: build random graph with 2 cluster

I need to build a graph with 2 clusters and random connectivities between them. I use

G = nx.powerlaw_cluster_graph(128, 2364, 0.5)

I need 128 nodes, 2364 edges, and 2 clusters. It returns an error and the wrong graph. Is there any way to do this? I need to get something like this: pic

Upvotes: 0

Views: 670

Answers (1)

sophros
sophros

Reputation: 16758

The answer is in the error message.
As per documentation I believe that instead of 2364 you need 2364/128 ~ 18 (the edges per node to be added).

This is not going to get you two linked clusters but rather one graph with connectivity guided by the last parameter.
To have two clusters connected I would create two separate random graphs (in the same way you do currently) and add a few random connections afterwards (randomly picking pairs of vertices - one from each graph). This seems easiest to me.

Upvotes: 2

Related Questions