code: def foreach(body, data, init_states):
      """Run a for loop with user-defined computation over NDArrays on dimension 0.
  
      This operator simulates a for loop and body has the computation for an iteration
      of the for loop. It runs the computation in body on each slice from the input
      NDArrays.
  
      body takes two arguments as input and outputs a tuple of two elements,
      as illustrated below::
  
          out, states = body(data1, states)
  
      data1 can be either an NDArray or a list of NDArrays. If data is an NDArray,
      data1 is an NDArray. Otherwise, data1 is a list of NDArrays and has the same
      size as data. states is a list of NDArrays and have the same size as init_states.
      Similarly, out can be either an NDArray or a list of NDArrays, which are concatenated
      as the first output of foreach; states from the last execution of body
      are the second output of foreach.
  
      The computation done by this operator is equivalent to the pseudo code below
      when the input data is NDArray::
  
          states = init_states
          outs = []
          for i in data.shape[0]:
              s = data[i]
              out, states = body(s, states)
              outs.append(out)
          outs = stack(*outs)
  
  
      Parameters
      ----------
      body : HybridBlock.
          Define computation in an iteration.
      data: an NDArray or a list of NDArrays.
          The input data.
      init_states: an NDArray or nested lists of NDArrays.
          The initial values of the loop states.
  
      Returns
      -------
      outputs: an NDArray or nested lists of NDArrays.
          The output data concatenated from the output of all iterations.
      states: an NDArray or nested lists of NDArrays.
          The loop states in the last iteration.
  
      Examples
      --------
      >>> step = lambda data, states: (data + states[0], [states[0] * 2])
      >>> data = mx.np.random.uniform(size=(2, 10))
      >>> states = [mx.np.random.uniform(size=(10))]
      >>> outs, states = npx.control_flow.foreach(step, data, states)
      """
      return _mx_nd_npx.foreach(body, data, init_states)
  
imports: from ..ndarray import numpy_extension
  from ..util import set_module
label_desc: Use image node_id 1 for calling a global function with example usage: foreach(body, data, init_states) and returns: _mx_nd_npx