code: def divergence_id(grad, l1_ratio=0.5):
      """Compute divergence + id of image gradient + id.
  
      Parameters
      ----------
      grad : ndarray, shape (4, nx, ny, nz, ...)
          where `img_shape` is the shape of the brain bounding box, and
          n_axes = len(img_shape).
  
      l1_ratio : float in the interval [0, 1]; optional (default .5)
          Constant that mixes L1 and spatial prior terms in the penalization.
  
      Returns
      -------
      res : ndarray, shape (nx, ny, nz, ...)
          The computed divergence + id operator.
  
      Raises
      ------
      RuntimeError
  
      """
      if not (0.0 <= l1_ratio <= 1.0):
          raise RuntimeError(
              f"l1_ratio must be in the interval [0, 1]; got {l1_ratio}"
          )
  
      res = np.zeros(grad.shape[1:])
  
      # the divergence part
      for d in range(grad.shape[0] - 1):
          this_grad = np.rollaxis(grad[d], d)
          this_res = np.rollaxis(res, d)
          this_res[:-1] += this_grad[:-1]
          this_res[1:-1] -= this_grad[:-2]
          if len(this_grad) > 1:
              this_res[-1] -= this_grad[-2]
  
      res *= 1.0 - l1_ratio
  
      # the identity part
      res -= l1_ratio * grad[-1]
  
      return res
  
file_path: nilearn/nilearn/decoding/_objective_functions.py
imports: from functools import partial
  import numpy
  from scipy import linalg
label_desc: Use image node_id 5 for calling a global function with example usage: divergence_id(grad, l1_ratio) and returns: res