code: def _sparse_spectral(A, dim=2):
      # Input adjacency matrix A
      # Uses sparse eigenvalue solver from scipy
      # Could use multilevel methods here, see Koren "On spectral graph drawing"
      import numpy as np
      import scipy as sp
  
      try:
          nnodes, _ = A.shape
      except AttributeError as err:
          msg = "sparse_spectral() takes an adjacency matrix as input"
          raise nx.NetworkXError(msg) from err
  
      # form Laplacian matrix
      # TODO: Rm csr_array wrapper in favor of spdiags array constructor when available
      D = sp.sparse.csr_array(
          sp.sparse.spdiags(A.sum(axis=1), 0, nnodes, nnodes)
      )
      L = D - A
  
      k = dim + 1
      # number of Lanczos vectors for ARPACK solver.What is the right scaling?
      ncv = max(2 * k + 1, int(np.sqrt(nnodes)))
      # return smallest k eigenvalues and eigenvectors
      eigenvalues, eigenvectors = sp.sparse.linalg.eigsh(
          L, k, which="SM", ncv=ncv
      )
      index = np.argsort(eigenvalues)[1:k]  # 0 index is zero eigenvalue
      return np.real(eigenvectors[:, index])
  
imports: import networkx
  from networkx.utils import np_random_state
label_desc: Use image node_id 14 for calling a global function with example usage: _sparse_spectral(A, dim) and returns: np