code: def from_masked_images(cls: Type[T], masked_images: Iterable[np.ndarray],
                             n_subjects: int) -> T:
          
          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)
docs: 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.