'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 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 micro5