code: def slice_generator(data, axis=0):
      """Return generator for yielding slices along `axis`
  
      Parameters
      ----------
      data : array-like
      axis : int or list or tuple
          If int, gives the axis.  If list or tuple, gives the combination of
          axes over which to iterate.  First axis is fastest changing in output.
  
      Examples
      --------
      >>> for i,d in slice_generator([[1,2],[3,4]]):
      ...     print(i, d)
      ...
      (0,) [1 2]
      (1,) [3 4]
      >>> for i,d in slice_generator([[1,2],[3,4]], axis=1):
      ...     print(i, d)
      ...
      (slice(None, None, None), 0) [1 3]
      (slice(None, None, None), 1) [2 4]
      """
      data = np.asarray(data)
      if type(axis) is int:
          for j in range(data.shape[axis]):
              ij = (slice(None, None, None),) * axis + (j,)
              yield ij, data[(slice(None, None, None),) * axis + (j,)]
          return
  
      # the total number of iterations to be made
      axis_lens = [data.shape[a] for a in axis]
      nmax = seq_prod(axis_lens)
  
      # calculate the 'divmod' parameter which is used to work out
      # which index to use to use for each axis during iteration
      mods = np.cumprod(axis_lens)
      divs = [1] + list(mods[:-1])
  
      # set up a full set of slices for the image, to be modified
      # at each iteration
      slice_template = [slice(0, s) for s in data.shape]
  
      for n in range(nmax):
          slices = slice_template[:]
          for a, div, mod in zip(axis, divs, mods):
              x = int(n / div % mod)
              slices[a] = x
          slices = tuple(slices)
          yield slices, data[slices]
  
file_path: nipy/nipy/core/utils/generators.py
imports: import numpy
  from nipy.utils import seq_prod
label_desc: Use image node_id 4 for calling a global function with example usage: slice_generator(data, axis) without return types