code: def add_self_loops(matrix, loop_value):
      
      shape = matrix.shape
      assert shape[0] == shape[1], "Error, matrix is not square"
  
      if isspmatrix(matrix):
          new_matrix = matrix.todok()
      else:
          new_matrix = matrix.copy()
  
      for i in range(shape[0]):
          new_matrix[i, i] = loop_value
  
      if isspmatrix(matrix):
          return new_matrix.tocsc()
  
      return new_matrix
docs: Add self-loops to the matrix by setting the diagonal
      to loop_value
      
      :param matrix: The matrix to add loops to
      :param loop_value: Value to use for self-loops
      :returns: The matrix with self-loops