code: def _set_diag(laplacian, value, norm_laplacian):
      """
      Set the diagonal of the laplacian matrix and convert it to a sparse
      format well suited for eigenvalue decomposition.
  
      Arguments
      ---------
      laplacian : array or sparse matrix
          The graph laplacian.
      value : float
          The value of the diagonal.
      norm_laplacian : bool
          Whether the value of the diagonal should be changed or not.
  
      Returns
      -------
      laplacian : array or sparse matrix
          An array of matrix in a form that is well suited to fast eigenvalue
          decomposition, depending on the bandwidth of the matrix.
      """
  
      n_nodes = laplacian.shape[0]
      # We need all entries in the diagonal to values
      if not sparse.isspmatrix(laplacian):
          if norm_laplacian:
              laplacian.flat[:: n_nodes + 1] = value
      else:
          laplacian = laplacian.tocoo()
          if norm_laplacian:
              diag_idx = laplacian.row == laplacian.col
              laplacian.data[diag_idx] = value
          # If the matrix has a small number of diagonals (as in the
          # case of structured matrices coming from images), the
          # dia format might be best suited for matvec products:
          n_diags = np.unique(laplacian.row - laplacian.col).size
          if n_diags <= 7:
              # 3 or less outer diagonals on each side
              laplacian = laplacian.todia()
          else:
              # csr has the fastest matvec and is thus best suited to
              # arpack
              laplacian = laplacian.tocsr()
      return laplacian
  
imports: import csv
  import numbers
  import warnings
  import scipy
  import pytest
  import numpy
  from scipy import sparse
  from scipy.sparse.linalg import eigsh
  from scipy.sparse.csgraph import connected_components
  from scipy.sparse.csgraph import laplacian
label_desc: Use image node_id 10 for calling a global function with example usage: _set_diag(laplacian, value, norm_laplacian) and returns: laplacian