This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.


degree_assortativity_coefficient(G, x='out', y='in', weight=None, nodes=None)[source]

Compute degree assortativity of graph.

Assortativity measures the similarity of connections in the graph with respect to the node degree.


G : NetworkX graph

x: string (‘in’,’out’)

The degree type for source node (directed graphs only).

y: string (‘in’,’out’)

The degree type for target node (directed graphs only).

weight: string or None, optional (default=None)

The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1. The degree is the sum of the edge weights adjacent to the node.

nodes: list or iterable (optional)

Compute degree assortativity only for nodes in container. The default is all nodes.


r : float

Assortativity of graph by degree.


This computes Eq. (21) in Ref. [R151] , where e is the joint probability distribution (mixing matrix) of the degrees. If G is directed than the matrix e is the joint probability of the user-specified degree type for the source and target.


[R151](1, 2) M. E. J. Newman, Mixing patterns in networks, Physical Review E, 67 026126, 2003
[R152]Foster, J.G., Foster, D.V., Grassberger, P. & Paczuski, M. Edge direction and the structure of networks, PNAS 107, 10815-20 (2010).


>>> G=nx.path_graph(4)
>>> r=nx.degree_assortativity_coefficient(G)
>>> print("%3.1f"%r)