Search code examples
graphnetworkx

Finding density of each community in a network using cdlib


I am using cdlib library to discover communities in a network using leiden algorithm. The method to discover communities is straightforward. The following code does it:

from cdlib import algorithms
import networkx as nx
G = nx.karate_club_graph()
coms = algorithms.leiden(G)

I am, however, stuck as to how to find density of each community. I will be grateful for any help. (Even though this question does not directly pertain to networkx library, I am tagging networkx as cdlib is not present).


Solution

  • You can use coms.scaled_density(summary=False) to calculate densities of the individual communities. Read doc for rest of the arguments.