class_docstr: Array with shape n_TRs, n_voxels, n_subjects.
class_docstr_tok: ["Array","with","shape","n_TRs",",","n_voxels",",","n_subjects","."]
docstr: Create a new instance of MaskedMultiSubjecData from masked images.
  
  Parameters
  ----------
  masked_images : iterator
      Images from multiple subjects to stack along 3rd dimension
  n_subjects : int
      Number of subjects; must match the number of images
  
  Returns
  -------
  T
      A new instance of MaskedMultiSubjectData
  
  Raises
  ------
  ValueError
      Images have different shapes.
  
      The number of images differs from n_subjects.
docstr_tok: ["Create","a","new","instance","of","MaskedMultiSubjecData","from","masked","images",".","Parameters","--","--","--","--","--","masked_images",":","iterator","Images","from","multiple","subjects","to","stack","along","3rd","dimension","n_subjects",":","int","Number","of","subjects",";","must","match","the","number","of","images","Returns","--","--","--","-","T","A","new","instance","of","MaskedMultiSubjectData","Raises","--","--","--","ValueError","Images","have","different","shapes",".","The","number","of","images","differs","from","n_subjects","."]
code: def from_masked_images(
      cls: Type[T], masked_images: Iterable[np.ndarray], n_subjects: int
  ) -> T:
      """Create a new instance of MaskedMultiSubjecData from masked images.
  
      Parameters
      ----------
      masked_images : iterator
          Images from multiple subjects to stack along 3rd dimension
      n_subjects : int
          Number of subjects; must match the number of images
  
      Returns
      -------
      T
          A new instance of MaskedMultiSubjectData
  
      Raises
      ------
      ValueError
          Images have different shapes.
  
          The number of images differs from n_subjects.
      """
      images_iterator = iter(masked_images)
      first_image = next(images_iterator)
      first_image_shape = first_image.T.shape
      result = np.empty(
          (first_image_shape[0], first_image_shape[1], n_subjects)
      )
      for n_images, image in enumerate(
          itertools.chain([first_image], images_iterator)
      ):
          image = image.T
          if image.shape != first_image_shape:
              raise ValueError(
                  "Image {} has different shape from first "
                  "image: {} != {}".format(
                      n_images, image.shape, first_image_shape
                  )
              )
          result[:, :, n_images] = image
      n_images += 1
      if n_images != n_subjects:
          raise ValueError(
              "n_subjects != number of images: {} != {}".format(
                  n_subjects, n_images
              )
          )
      return result.view(cls)
  
file_path: brainiak/brainiak/image.py
imports: import itertools
  from typing import Optional, Iterable, Sequence, Type, TypeVar
  import numpy
  from nibabel.spatialimages import SpatialImage
label_desc: Use image node_id 1 for calling the MaskedMultiSubjectData obj's underlying member method code with example usage: obj.from_masked_images(cls, masked_images, n_subjects) and returns: result