code: def parcels(data, labels=None, exclude=()):
      """Return a generator for ``[data == label for label in labels]``
  
      If labels is None, labels = numpy.unique(data).  Each label in labels can be
      a sequence, in which case the value returned for that label union::
  
          [numpy.equal(data, l) for l in label]
  
      Parameters
      ----------
      data : image or array-like
          Either an image (with ``get_fdata`` method returning ndarray) or an
          array-like
      labels : iterable, optional
          A sequence of labels for which to return indices within `data`. The
          elements in `labels` can themselves be lists, tuples, in which case the
          indices returned are for all values in `data` matching any of the items
          in the list, tuple.
      exclude : iterable, optional
          Values in `labels` for which you do not want to return a parcel.
  
      Returns
      -------
      gen : generator
          generator yielding a array of boolean indices into `data` for which ``data
          == label``, for each element in `label`.
  
      Examples
      --------
      >>> for p in parcels([[1,1],[2,1]]):
      ...     print(p)
      ...
      [[ True  True]
       [False  True]]
      [[False False]
       [ True False]]
      >>> for p in parcels([[1,1],[2,3]], labels=[2,3]):
      ...     print(p)
      ...
      [[False False]
       [ True False]]
      [[False False]
       [False  True]]
      >>> for p in parcels([[1,1],[2,3]], labels=[(2,3),2]):
      ...     print(p)
      ...
      [[False False]
       [ True  True]]
      [[False False]
       [ True False]]
      """
      # Get image data or make array from array-like
      try:
          data = data.get_fdata()
      except AttributeError:
          data = np.asarray(data)
      if labels is None:
          labels = np.unique(data)
      for label in labels:
          if label in exclude:
              continue
          if type(label) not in [type(()), type([])]:
              yield np.equal(data, label)
          else:
              v = 0
              for l in label:
                  v += np.equal(data, l)
              yield v.astype(bool)
  
file_path: nipy/nipy/core/utils/generators.py
imports: import numpy
  from nipy.utils import seq_prod
label_desc: Use image node_id 1 for calling a global function with example usage: parcels(data, labels, exclude) without return types