networkx.classes.function.density¶

density
(G)[source]¶ Returns the density of a graph.
The density for undirected graphs is
\[d = \frac{2m}{n(n1)},\]and for directed graphs is
\[d = \frac{m}{n(n1)},\]where
n
is the number of nodes andm
is the number of edges inG
.Notes
The density is 0 for a graph without edges and 1 for a complete graph. The density of multigraphs can be higher than 1.
Self loops are counted in the total number of edges so graphs with self loops can have density higher than 1.