code: def prepare_mvpa_data(images, conditions, mask):
      """Prepare data for activity-based model training and prediction.
  
      Average the activity within epochs and z-scoring within subject.
  
      Parameters
      ----------
      images: Iterable[SpatialImage]
          Data.
      conditions: List[UniqueLabelConditionSpec]
          Condition specification.
      mask: np.ndarray
          Mask to apply to each image.
  
      Returns
      -------
      processed_data: 2D array in shape [num_voxels, num_epochs]
          averaged epoch by epoch processed data
      labels: 1D array
          contains labels of the data
      """
      activity_data = list(mask_images(images, mask, np.float32))
      epoch_info = generate_epochs_info(conditions)
      num_epochs = len(epoch_info)
      (d1, _) = activity_data[0].shape
      processed_data = np.empty([d1, num_epochs])
      labels = np.empty(num_epochs)
      subject_count = [
          0
      ]  # counting the epochs per subject for z-scoring
      cur_sid = -1
      # averaging
      for idx, epoch in enumerate(epoch_info):
          labels[idx] = epoch[0]
          if cur_sid != epoch[1]:
              subject_count.append(0)
              cur_sid = epoch[1]
          subject_count[-1] += 1
          processed_data[:, idx] = np.mean(
              activity_data[cur_sid][:, epoch[2] : epoch[3]], axis=1
          )
      # z-scoring
      cur_epoch = 0
      for i in subject_count:
          if i > 1:
              processed_data[:, cur_epoch : cur_epoch + i] = zscore(
                  processed_data[:, cur_epoch : cur_epoch + i],
                  axis=1,
                  ddof=0,
              )
          cur_epoch += i
      # if zscore fails (standard deviation is zero),
      # set all values to be zero
      processed_data = np.nan_to_num(processed_data)
  
      return processed_data, labels
  
file_path: brainiak/brainiak/fcma/preprocessing.py
imports: import math
  import time
  import numpy
  import logging
  from scipy.stats.mstats import zscore
  from mpi4py import MPI
  from enum import Enum
  from ..image import mask_images, multimask_images
label_desc: Use image node_id 6 for calling a global function with example usage: prepare_mvpa_data(images, conditions, mask) and returns: processed_data,  labels