code: def _mask_and_reduce(
      masker,
      imgs,
      confounds=None,
      reduction_ratio="auto",
      n_components=None,
      random_state=None,
      memory_level=0,
      memory=Memory(location=None),
      n_jobs=1,
  ):
      """Mask and reduce provided 4D images with given masker.
  
      Uses a PCA (randomized for small reduction ratio) or a range finding matrix
      on time series to reduce data size in time direction. For multiple images,
      the concatenation of data is returned, either as an ndarray or a memorymap
      (useful for big datasets that do not fit in memory).
  
      Parameters
      ----------
      masker : NiftiMasker or MultiNiftiMasker
          Instance used to mask provided data.
  
      imgs : list of 4D Niimg-like objects
          See :ref:`extracting_data`.
          List of subject data to mask, reduce and stack.
  
      confounds : CSV file path or numpy ndarray, or pandas DataFrame, optional
          This parameter is passed to signal.clean. Please see the
          corresponding documentation for details.
  
      reduction_ratio : 'auto' or float between 0. and 1., default='auto'
          - Between 0. or 1. : controls data reduction in the temporal domain
          , 1. means no reduction, < 1. calls for an SVD based reduction.
          - if set to 'auto', estimator will set the number of components per
            reduced session to be n_components.
  
      n_components : integer, optional
          Number of components per subject to be extracted by dimension reduction
  
      random_state : int or RandomState, optional
          Pseudo number generator state used for random sampling.
  
      memory_level : integer, default=0
          Integer indicating the level of memorization. The higher, the more
          function calls are cached.
  
      memory : joblib.Memory, optional
          Used to cache the function calls.
  
      n_jobs : integer, default=1
          The number of CPUs to use to do the computation. -1 means
          'all CPUs', -2 'all CPUs but one', and so on.
  
      Returns
      -------
      data : ndarray or memorymap
          Concatenation of reduced data.
  
      """
      if not hasattr(imgs, "__iter__"):
          imgs = [imgs]
  
      if reduction_ratio == "auto":
          if n_components is None:
              # Reduction ratio is 1 if
              # neither n_components nor ratio is provided
              reduction_ratio = 1
      else:
          reduction_ratio = (
              1 if reduction_ratio is None else float(reduction_ratio)
          )
          if not 0 <= reduction_ratio <= 1:
              raise ValueError(
                  "Reduction ratio should be between 0.0 and 1.0, "
                  f"got {reduction_ratio:.2f}"
              )
  
      if confounds is None:
          confounds = itertools.repeat(confounds)
  
      if reduction_ratio == "auto":
          n_samples = n_components
          reduction_ratio = None
      else:
          # We'll let _mask_and_reduce_single decide on the number of
          # samples based on the reduction_ratio
          n_samples = None
  
      data_list = Parallel(n_jobs=n_jobs)(
          delayed(_mask_and_reduce_single)(
              masker,
              img,
              confound,
              reduction_ratio=reduction_ratio,
              n_samples=n_samples,
              memory=memory,
              memory_level=memory_level,
              random_state=random_state,
          )
          for img, confound in zip(imgs, confounds)
      )
  
      subject_n_samples = [
          subject_data.shape[0] for subject_data in data_list
      ]
  
      n_samples = np.sum(subject_n_samples)
      n_voxels = int(np.sum(safe_get_data(masker.mask_img_)))
      dtype = (
          np.float64
          if data_list[0].dtype.type is np.float64
          else np.float32
      )
      data = np.empty((n_samples, n_voxels), order="F", dtype=dtype)
  
      current_position = 0
      for i, next_position in enumerate(np.cumsum(subject_n_samples)):
          data[current_position:next_position] = data_list[i]
          current_position = next_position
          # Clear memory as fast as possible: remove the reference on
          # the corresponding block of data
          data_list[i] = None
      return data
  
imports: import glob
  import itertools
  from math import ceil
  import numpy
  from joblib import Memory, Parallel, delayed
  from scipy import linalg
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.linear_model import LinearRegression
  from sklearn.utils import check_random_state
  from sklearn.utils.extmath import randomized_svd, svd_flip
  import nilearn
  from nilearn._utils.masker_validation import check_embedded_masker
  from nilearn.maskers import NiftiMapsMasker
  from .._utils import fill_doc
  from .._utils.cache_mixin import CacheMixin, cache
  from .._utils.niimg import safe_get_data
  from .._utils.niimg_conversions import resolve_globbing
  from ..signal import row_sum_of_squares
label_desc: Use image node_id 2 for calling a global function with example usage: _mask_and_reduce(masker, imgs, confounds, reduction_ratio, n_components, random_state, memory_level, memory, n_jobs) and returns: data