density

Contents

density#

graph_tool.stats.density(g)[git][source]#

Return the density of the graph.

Parameters:
gGraph

Graph to be used.

Returns:
rhofloat

The number of edges divided by the number of pairs of distinct vertices, \(E/\binom{V}{2}\) for undirected graphs and \(E/[V(V-1)]\) for directed ones.

See also

vertex_average

Average vertex degree

graph_tool.structure.densest_subgraph

Subgraph of largest density

Notes

Parallel edges and self-loops are counted as edges, so that the density can exceed one for multigraphs. For graphs with fewer than two vertices, the density is defined as zero.

Examples

>>> g = gt.collection.data["karate"]
>>> print(gt.density(g))
0.1390...