code: def gather_tree_py(values, parents):
      """Gathers path through a tree backwards from the leave nodes. Used
      to reconstruct beams given their parents."""
      beam_length = values.shape[0]
      num_beams = values.shape[1]
      res = np.zeros_like(values)
      res[-1, :] = values[-1, :]
      for beam_id in range(num_beams):
          parent = parents[-1][beam_id]
          for level in reversed(range(beam_length - 1)):
              res[level, beam_id] = values[level][parent]
              parent = parents[level][parent]
      return np.array(res).astype(values.dtype)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from collections import namedtuple
  import numpy
  import tensorflow
  from tensorflow.python.util import nest
label_desc: Use image node_id 1 for calling a global function with example usage: gather_tree_py(values, parents) and returns: np