code: def test_as_numpy(self):
      t = trajectory.Trajectory()
      shape = (3, 4)
  
      # We'll have `ts` observations and `ts-1` actions and rewards.
      ts = 5
      num_actions = 6
      observations = np.random.uniform(size=(ts,) + shape)
      actions = np.random.choice(range(num_actions), size=(ts - 1,))
      rewards = np.random.choice([-1, 0, 1], size=(ts - 1,))
      squares = np.arange(ts - 1) ** 2
      cubes = np.arange(ts - 1) ** 3
  
      def get_info(i):
          return {"sq": squares[i], "cu": cubes[i]}
  
      # First time-step has no reward.
      t.add_time_step(
          observation=observations[0],
          done=False,
          action=actions[0],
          info=get_info(0),
      )
      for i in range(1, ts - 1):
          t.add_time_step(
              observation=observations[i],
              done=False,
              raw_reward=rewards[i - 1],
              processed_reward=rewards[i - 1],
              action=actions[i],
              info=get_info(i),
          )
      # Last time-step has no action.
      t.add_time_step(
          observation=observations[-1],
          done=False,
          raw_reward=rewards[-1],
          processed_reward=rewards[-1],
      )
  
      traj_np = t.as_numpy
  
      self.assertAllEqual(observations, traj_np[0])
      self.assertAllEqual(actions, traj_np[1])
      self.assertAllEqual(rewards, traj_np[2])
  
      self.assertAllEqual(squares, traj_np[4]["sq"])
      self.assertAllEqual(cubes, traj_np[4]["cu"])
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import numpy
  from tensor2tensor.envs import time_step
  from tensor2tensor.envs import trajectory
  import tensorflow.compat.v1
  from tensorflow.compat.v1.io import gfile
label_desc: Use image node_id 7 for calling the TrajectoryTest obj's underlying member method code with example usage: obj.test_as_numpy() and returns: dict