NetworkX

Previous topic

networkx.algorithms.cluster.clustering

Next topic

networkx.algorithms.cluster.square_clustering

networkx.algorithms.cluster.average_clustering

networkx.algorithms.cluster.average_clustering(G, weighted=False)

Compute average clustering coefficient.

A clustering coefficient for the whole graph is the average,

C = \frac{1}{n}\sum_{v \in G} c_v,

where n is the number of nodes in G.

Parameters :

G : graph

A networkx graph

weighted : bool, optional

If True use weights on edges in computing clustering coefficients.

Returns :

out : float

Average clustering

Notes

This is a space saving routine; it might be faster to use clustering to get a list and then take the average.

Self loops are ignored.

References

[R102]Generalizations of the clustering coefficient to weighted complex networks by J. Saramäki, M. Kivelä, J.-P. Onnela, K. Kaski, and J. Kertész, Physical Review E, 75 027105 (2007). http://jponnela.com/web_documents/a9.pdf

Examples

>>> G=nx.complete_graph(5)
>>> print(nx.average_clustering(G))
1.0