code: def gym_space_encode(gym_space, observation):
      # We should return something that generator_utils.to_example can consume.
      if isinstance(gym_space, Discrete):
          return [observation]
  
      if isinstance(gym_space, Box):
          return observation.reshape(-1).tolist()
  
      raise NotImplementedError
  
file_path: tensor2tensor/tensor2tensor/envs/gym_spaces_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from gym.spaces import Box
  from gym.spaces import Discrete
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 4 for calling a global function with example usage: gym_space_encode(gym_space, observation) and returns: list, observation