code: def _create_trajectory(
      observation,
      action,
      policy_info,
      reward,
      discount,
      step_type,
      next_step_type,
      name_scope,
  ):
      """Create a Trajectory composed of either Tensors or numpy arrays.
  
      The input `discount` is used to infer the outer shape of the inputs,
      as it is always expected to be a singleton array with scalar inner shape.
  
      Args:
        observation: (possibly nested tuple of) `Tensor` or `np.ndarray`; all shaped
          `[B, ...]`, `[T, ...]`, or `[B, T, ...]`.
        action: (possibly nested tuple of) `Tensor` or `np.ndarray`; all shaped `[B,
          ...]`, `[T, ...]`, or `[B, T, ...]`.
        policy_info: (possibly nested tuple of) `Tensor` or `np.ndarray`; all shaped
          `[B, ...]`, `[T, ...]`, or `[B, T, ...]`.
        reward: (possibly nested tuple of) `Tensor` or `np.ndarray`; all shaped `[B,
          ...]`, `[T, ...]`, or `[B, T, ...]`.
        discount: A floating point vector `Tensor` or `np.ndarray`; shaped `[B]`,
          `[T]`, or `[B, T]` (optional).
        step_type: `Tensor` or `np.ndarray` of `ts.StepType`, shaped `[B]`, `[T]`,
          or `[B, T]`.
        next_step_type: `Tensor` or `np.ndarray` of `ts.StepType`, shaped `[B]`,
          `[T]`, or `[B, T]`.
        name_scope: Python string, name to use when creating tensors.
  
      Returns:
        A `Trajectory` instance.
      """
      if nest_utils.has_tensors(
          observation, action, policy_info, reward, discount
      ):
          with tf.name_scope(name_scope):
              discount = tf.identity(discount)
              shape = tf.shape(input=discount)
              make_tensors = lambda struct: tf.nest.map_structure(
                  tf.identity, struct
              )
              return Trajectory(
                  step_type=tf.fill(shape, step_type),
                  observation=make_tensors(observation),
                  action=make_tensors(action),
                  policy_info=make_tensors(policy_info),
                  next_step_type=tf.fill(shape, next_step_type),
                  reward=make_tensors(reward),
                  discount=discount,
              )
      else:
          discount = np.asarray(discount)
          shape = discount.shape
          make_arrays = lambda struct: tf.nest.map_structure(
              np.asarray, struct
          )
          return Trajectory(
              step_type=np.full(shape, step_type),
              observation=make_arrays(observation),
              action=make_arrays(action),
              policy_info=make_arrays(policy_info),
              next_step_type=np.full(shape, next_step_type),
              reward=make_arrays(reward),
              discount=discount,
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import pprint
  from typing import NamedTuple, Optional
  import numpy
  import tensorflow
  from tf_agents.trajectories import policy_step
  from tf_agents.trajectories import time_step
  from tf_agents.typing import types
  from tf_agents.utils import composite
  from tf_agents.utils import nest_utils
  from tf_agents.utils import value_ops
label_desc: Use image node_id 1 for calling a global function with example usage: _create_trajectory(observation, action, policy_info, reward, discount, step_type, next_step_type, name_scope) and returns: Trajectory, Trajectory