code: def _laplacian_sparse(graph, normed=False, return_diag=False):
      n_nodes = graph.shape[0]
      if not graph.format == "coo":
          lap = (-graph).tocoo()
      else:
          lap = -graph.copy()
      diag_mask = lap.row == lap.col
      if not diag_mask.sum() == n_nodes:
          # The sparsity pattern of the matrix has holes on the diagonal,
          # we need to fix that
          diag_idx = lap.row[diag_mask]
          diagonal_holes = list(
              set(range(n_nodes)).difference(diag_idx)
          )
          new_data = np.concatenate(
              [lap.data, np.ones(len(diagonal_holes))]
          )
          new_row = np.concatenate([lap.row, diagonal_holes])
          new_col = np.concatenate([lap.col, diagonal_holes])
          lap = sparse.coo_matrix(
              (new_data, (new_row, new_col)), shape=lap.shape
          )
          diag_mask = lap.row == lap.col
  
      lap.data[diag_mask] = 0
      w = -np.asarray(lap.sum(axis=1)).squeeze()
      if normed:
          w = np.sqrt(w)
          w_zeros = w == 0
          w[w_zeros] = 1
          lap.data /= w[lap.row]
          lap.data /= w[lap.col]
          lap.data[diag_mask] = (
              1 - w_zeros[lap.row[diag_mask]]
          ).astype(lap.data.dtype)
      else:
          lap.data[diag_mask] = w[lap.row[diag_mask]]
  
      if return_diag:
          return lap, w
      return lap
  
imports: import numpy
  from scipy import sparse
  from .validation import check_array
  from .graph_shortest_path import graph_shortest_path
label_desc: Use image node_id 3 for calling a global function with example usage: _laplacian_sparse(graph, normed, return_diag) and returns: lap, lap,  w