code: def scan(func, init_val, x, axis, exclusive, reverse):
      if reverse:
          x = np.flip(x, axis)
      y = func(x, axis)
      if exclusive:
          # Make first element to `init_val` on the axis.
          shape = y.shape
          if axis < 0:
              ndim = len(shape)
              axis += ndim
          shape_3d = ()
          shape_3d += (np.prod(shape[:axis], dtype=np.int64),)
          shape_3d += (shape[axis],)
          shape_3d += (np.prod(shape[(axis + 1) :], dtype=np.int64),)
          y = np.reshape(y, shape_3d)
          scan_size = shape[axis]
          y[:, 1:scan_size, :] = y[:, : (scan_size - 1), :]
          y[:, 0, :] = init_val
          y = np.reshape(y, shape)
      if reverse:
          y = np.flip(y, axis)
      return y
  
imports: from __future__ import division
  from six.moves import range
  import itertools
  import numpy
label_desc: Use image node_id 21 for calling a global function with example usage: scan(func, init_val, x, axis, exclusive, reverse) and returns: y