code: def _make_laplacian_sparse(edges, weights):
      """Sparse implementation."""
      pixel_nb = edges.max() + 1
      diag = np.arange(pixel_nb)
      i_indices = np.hstack((edges[0], edges[1]))
      j_indices = np.hstack((edges[1], edges[0]))
      data = np.hstack((-weights, -weights))
      lap = sparse.coo_matrix(
          (data, (i_indices, j_indices)), shape=(pixel_nb, pixel_nb)
      )
      connect = -np.ravel(lap.sum(axis=1))
      lap = sparse.coo_matrix(
          (
              np.hstack((data, connect)),
              (
                  np.hstack((i_indices, diag)),
                  np.hstack((j_indices, diag)),
              ),
          ),
          shape=(pixel_nb, pixel_nb),
      )
      return lap.tocsr()
  
file_path: nilearn/nilearn/_utils/segmentation.py
imports: import warnings
  import numpy
  from scipy import ndimage, sparse
  from scipy.sparse.linalg import cg
  from sklearn.utils import as_float_array
label_desc: Use image node_id 4 for calling a global function with example usage: _make_laplacian_sparse(edges, weights) and returns: lap