def spectral_ordering(G, weight='weight', normalized=False, tol=1e-08, method='tracemin_pcg'):
    "Compute the spectral_ordering of a graph.\n\n    The spectral ordering of a graph is an ordering of its nodes where nodes\n    in the same weakly connected components appear contiguous and ordered by\n    their corresponding elements in the Fiedler vector of the component.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n        A graph.\n\n    weight : object, optional (default: None)\n        The data key used to determine the weight of each edge. If None, then\n        each edge has unit weight.\n\n    normalized : bool, optional (default: False)\n        Whether the normalized Laplacian matrix is used.\n\n    tol : float, optional (default: 1e-8)\n        Tolerance of relative residual in eigenvalue computation.\n\n    method : string, optional (default: 'tracemin_pcg')\n        Method of eigenvalue computation. It must be one of the tracemin\n        options shown below (TraceMIN), 'lanczos' (Lanczos iteration)\n        or 'lobpcg' (LOBPCG).\n\n        The TraceMIN algorithm uses a linear system solver. The following\n        values allow specifying the solver to be used.\n\n        =============== ========================================\n        Value           Solver\n        =============== ========================================\n        'tracemin_pcg'  Preconditioned conjugate gradient method\n        'tracemin_chol' Cholesky factorization\n        'tracemin_lu'   LU factorization\n        =============== ========================================\n\n    Returns\n    -------\n    spectral_ordering : NumPy array of floats.\n        Spectral ordering of nodes.\n\n    Raises\n    ------\n    NetworkXError\n        If G is empty.\n\n    Notes\n    -----\n    Edge weights are interpreted by their absolute values. For MultiGraph's,\n    weights of parallel edges are summed. Zero-weighted edges are ignored.\n\n    To use Cholesky factorization in the TraceMIN algorithm, the\n    :samp:`scikits.sparse` package must be installed.\n\n    See Also\n    --------\n    laplacian_matrix\n    "
    if (len(G) == 0):
        raise nx.NetworkXError('graph is empty.')
    G = _preprocess_graph(G, weight)
    find_fiedler = _get_fiedler_func(method)
    order = []
    for component in nx.connected_components(G):
        size = len(component)
        if (size > 2):
            L = nx.laplacian_matrix(G, component)
            x = (None if (method != 'lobpcg') else _rcm_estimate(G, component))
            (sigma, fiedler) = find_fiedler(L, x, normalized, tol)
            sort_info = zip(fiedler, range(size), component)
            order.extend((u for (x, c, u) in sorted(sort_info)))
        else:
            order.extend(component)
    return order
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.

Parameters
----------
G : NetworkX graph
    A graph.

weight : object, optional (default: None)
    The data key used to determine the weight of each edge. If None, then
    each edge has unit weight.

normalized : bool, optional (default: False)
    Whether the normalized Laplacian matrix is used.

tol : float, optional (default: 1e-8)
    Tolerance of relative residual in eigenvalue computation.

method : string, 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.

    =============== ========================================
    Value           Solver
    =============== ========================================
    'tracemin_pcg'  Preconditioned conjugate gradient method
    'tracemin_chol' Cholesky factorization
    'tracemin_lu'   LU factorization
    =============== ========================================

Returns
-------
spectral_ordering : NumPy array of floats.
    Spectral ordering of nodes.

Raises
------
NetworkXError
    If G is empty.

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

To use Cholesky factorization in the TraceMIN algorithm, the
:samp:`scikits.sparse` package must be installed.

See Also
--------
laplacian_matrix
def spectral_ordering(G, weight='weight', normalized=False, tol=1e-08, method='tracemin_pcg'):
    "Compute the spectral_ordering of a graph.\n\n    The spectral ordering of a graph is an ordering of its nodes where nodes\n    in the same weakly connected components appear contiguous and ordered by\n    their corresponding elements in the Fiedler vector of the component.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n        A graph.\n\n    weight : object, optional (default: None)\n        The data key used to determine the weight of each edge. If None, then\n        each edge has unit weight.\n\n    normalized : bool, optional (default: False)\n        Whether the normalized Laplacian matrix is used.\n\n    tol : float, optional (default: 1e-8)\n        Tolerance of relative residual in eigenvalue computation.\n\n    method : string, optional (default: 'tracemin_pcg')\n        Method of eigenvalue computation. It must be one of the tracemin\n        options shown below (TraceMIN), 'lanczos' (Lanczos iteration)\n        or 'lobpcg' (LOBPCG).\n\n        The TraceMIN algorithm uses a linear system solver. The following\n        values allow specifying the solver to be used.\n\n        =============== ========================================\n        Value           Solver\n        =============== ========================================\n        'tracemin_pcg'  Preconditioned conjugate gradient method\n        'tracemin_chol' Cholesky factorization\n        'tracemin_lu'   LU factorization\n        =============== ========================================\n\n    Returns\n    -------\n    spectral_ordering : NumPy array of floats.\n        Spectral ordering of nodes.\n\n    Raises\n    ------\n    NetworkXError\n        If G is empty.\n\n    Notes\n    -----\n    Edge weights are interpreted by their absolute values. For MultiGraph's,\n    weights of parallel edges are summed. Zero-weighted edges are ignored.\n\n    To use Cholesky factorization in the TraceMIN algorithm, the\n    :samp:`scikits.sparse` package must be installed.\n\n    See Also\n    --------\n    laplacian_matrix\n    "
    if (len(G) == 0):
        raise nx.NetworkXError('graph is empty.')
    G = _preprocess_graph(G, weight)
    find_fiedler = _get_fiedler_func(method)
    order = []
    for component in nx.connected_components(G):
        size = len(component)
        if (size > 2):
            L = nx.laplacian_matrix(G, component)
            x = (None if (method != 'lobpcg') else _rcm_estimate(G, component))
            (sigma, fiedler) = find_fiedler(L, x, normalized, tol)
            sort_info = zip(fiedler, range(size), component)
            order.extend((u for (x, c, u) in sorted(sort_info)))
        else:
            order.extend(component)
    return order