spectral_ordering(G, weight='weight', normalized=False, tol=1e-08, method='tracemin_pcg', seed=None)[source]#

Compute the spectral_ordering of a graph.

The spectral ordering of a graph is an ordering of its nodes where nodes in the same weakly connected components appear contiguous and ordered by their corresponding elements in the Fiedler vector of the component.

GNetworkX graph

A graph.

weightobject, optional (default: None)

The data key used to determine the weight of each edge. If None, then each edge has unit weight.

normalizedbool, optional (default: False)

Whether the normalized Laplacian matrix is used.

tolfloat, optional (default: 1e-8)

Tolerance of relative residual in eigenvalue computation.

methodstring, optional (default: ‘tracemin_pcg’)

Method of eigenvalue computation. It must be one of the tracemin options shown below (TraceMIN), ‘lanczos’ (Lanczos iteration) or ‘lobpcg’ (LOBPCG).

The TraceMIN algorithm uses a linear system solver. The following values allow specifying the solver to be used.




Preconditioned conjugate gradient method


LU factorization

seedinteger, random_state, or None (default)

Indicator of random number generation state. See Randomness.

spectral_orderingNumPy array of floats.

Spectral ordering of nodes.


If G is empty.

See also



Edge weights are interpreted by their absolute values. For MultiGraph’s, weights of parallel edges are summed. Zero-weighted edges are ignored.