code: def numpy_scan(f, init, xs, reverse=False, mask=None):
      states = init
      outputs = []
  
      if mask is not None:
          x, mask = xs
          x = np.flip(x, axis=0) if reverse else x
          mask = np.flip(mask, axis=0) if reverse else mask
  
          for each_x, each_mask in zip(x, mask):
              states, output = f(states, (each_x, each_mask))
              outputs.append(output)
      else:
          xs = np.flip(xs, axis=0) if reverse else xs
  
          for x in xs:
              states, output = f(states, x)
              outputs.append(output)
  
      outputs = np.array(outputs)
  
      if reverse:
          outputs = np.flip(outputs, axis=0)
  
      return states, outputs
  
file_path: keras/keras/backend/numpy/rnn.py
imports: import numpy
  import tree
  from keras.utils.nest import pack_sequence_as
label_desc: Use image node_id 5 for calling a global function with example usage: numpy_scan(f, init, xs, reverse, mask) and returns: states,  outputs