code: def test_truncate_and_last_n_observations_np(self):
      t = trajectory.Trajectory()
      ts = 5
      shape = (3, 4)
      for _ in range(ts):
          t.add_time_step(
              observation=np.random.uniform(size=shape), done=False
          )
  
      original_obs = np.copy(t.observations_np)
      self.assertEqual((ts,) + shape, original_obs.shape)
  
      # Now let's just get the observations from the last 2 steps.
      num_to_keep = 2
      truncated_original_obs = original_obs[-num_to_keep:, ...]
  
      # Let's get the last `num_to_keep` observations
      last_n_observations_np = np.copy(
          t.last_n_observations_np(n=num_to_keep)
      )
  
      # Now truncate the trajectory and get the same.
      _ = t.truncate(num_to_keep=num_to_keep)
      truncated_np = np.copy(t.observations_np)
  
      # These should be the expected length.
      self.assertEqual((2,) + shape, last_n_observations_np.shape)
      self.assertEqual((2,) + shape, truncated_np.shape)
  
      # Test the last `num_to_keep` are the same.
      self.assertAllEqual(truncated_np, truncated_original_obs)
      self.assertAllEqual(
          last_n_observations_np, truncated_original_obs
      )
  
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 6 for calling the TrajectoryTest obj's underlying member method code with example usage: obj.test_truncate_and_last_n_observations_np() without return types