code: def _solve_cg(lap_sparse, B, tol):
      """Solve lap_sparse X_i = B_i for each phase i, using the conjugate \
      gradient method.
  
      For each pixel, the label i corresponding to the maximal X_i is returned.
      """
      lap_sparse = lap_sparse.tocsc()
      X = []
      for i in range(len(B)):
          x0 = cg(lap_sparse, -B[i].todense(), tol=tol, atol="legacy")[
              0
          ]
          X.append(x0)
  
      X = np.array(X)
      X = np.argmax(X, axis=0)
      return X
  
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 10 for calling a global function with example usage: _solve_cg(lap_sparse, B, tol) and returns: X