code: def iter_axis(img, axis, asarray=False):
      """Return generator to slice an image `img` over `axis`
  
      Parameters
      ----------
      img : ``Image`` instance
      axis : int or str
          axis identifier, either name or axis number
      asarray : {False, True}, optional
  
      Returns
      -------
      g : generator
          such that list(g) returns a list of slices over `axis`.  If `asarray` is
          `False` the slices are images.  If `asarray` is True, slices are the
          data from the images.
  
      Examples
      --------
      >>> data = np.arange(24).reshape((4,3,2))
      >>> img = Image(data, AffineTransform('ijk', 'xyz', np.eye(4)))
      >>> slices = list(iter_axis(img, 'j'))
      >>> len(slices)
      3
      >>> slices[0].shape
      (4, 2)
      >>> slices = list(iter_axis(img, 'k', asarray=True))
      >>> slices[1].sum() == data[:,:,1].sum()
      True
      """
      rimg = rollimg(img, axis)
      for i in range(rimg.shape[0]):
          if asarray:
              yield rimg[i].get_fdata()
          else:
              yield rimg[i]
  
imports: import warnings
  from copy import copy
  from itertools import chain
  import numpy
  from nibabel.onetime import auto_attr
  from ..reference.array_coords import ArrayCoordMap
  from ..reference.coordinate_map import AffineTransform, CoordinateSystem, input_axis_index
label_desc: Use image node_id 5 for calling a global function with example usage: iter_axis(img, axis, asarray) without return types