code: def signals_to_img_labels(
      signals, labels_img, mask_img=None, background_label=0, order="F"
  ):
      """Create image from region signals defined as labels.
  
      The same region signal is used for each :term:`voxel` of the
      corresponding 3D volume.
  
      labels_img, mask_img must have the same shapes and affines.
  
      .. versionchanged:: 0.9.2
          Support 1D signals.
  
      Parameters
      ----------
      signals : :class:`numpy.ndarray`
          1D or 2D array.
          If this is a 1D array, it must have as many elements as there are
          regions in the labels_img.
          If it is 2D, it should have the shape
          (number of scans, number of regions in labels_img).
  
      labels_img : Niimg-like object
          See :ref:`extracting_data`.
          Region definitions using labels.
  
      mask_img : Niimg-like object, optional
          See :ref:`extracting_data`.
          Boolean array giving voxels to process. integer arrays also accepted,
          In this array, zero means False, non-zero means True.
  
      background_label : number, default=0
          Label to use for "no region".
  
      order : :obj:`str`, default="F"
          Ordering of output array ("C" or "F").
  
      Returns
      -------
      img : :class:`nibabel.nifti1.Nifti1Image`
          Reconstructed image. dtype is that of "signals", affine and shape are
          those of labels_img.
  
      See Also
      --------
      nilearn.regions.img_to_signals_labels
      nilearn.regions.signals_to_img_maps
      nilearn.maskers.NiftiLabelsMasker : Signal extraction on labels
          images e.g. clusters
  
      """
      labels_img = _utils.check_niimg_3d(labels_img)
  
      labels, labels_data = _get_labels_data(
          labels_img, labels_img, mask_img, background_label
      )
  
      signals = np.asarray(signals)
  
      target_shape = labels_img.shape[:3]
      # nditer is not available in numpy 1.3: using multiple loops.
      # Using these loops still gives a much faster code (6x) than this one:
      # for n, label in enumerate(labels):
      #     data[labels_data == label, :] = signals[:, n]
      if signals.ndim == 2:
          target_shape = target_shape + (signals.shape[0],)
  
      data = np.zeros(target_shape, dtype=signals.dtype, order=order)
      labels_dict = {label: n for n, label in enumerate(labels)}
      # optimized for "data" in F order.
      for k in range(labels_data.shape[2]):
          for j in range(labels_data.shape[1]):
              for i in range(labels_data.shape[0]):
                  label = labels_data[i, j, k]
                  num = labels_dict.get(label)
                  if num is not None:
                      if signals.ndim == 2:
                          data[i, j, k, :] = signals[:, num]
                      else:
                          data[i, j, k] = signals[num]
  
      return new_img_like(labels_img, data, labels_img.affine)
  
file_path: nilearn/nilearn/regions/signal_extraction.py
imports: import warnings
  import numpy
  from nibabel import Nifti1Image
  from scipy import linalg, ndimage
  from ..None import _utils, masking
  from .._utils.niimg import safe_get_data
  from ..image import new_img_like
label_desc: Use image node_id 7 for calling a global function with example usage: signals_to_img_labels(signals, labels_img, mask_img, background_label, order) and returns: new_img_like