density#
- graph_tool.stats.density(g)[git][source]#
Return the density of the graph.
- Parameters:
- g
Graph Graph to be used.
- g
- Returns:
- rho
float 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.
- rho
See also
vertex_averageAverage vertex degree
graph_tool.structure.densest_subgraphSubgraph 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...