class_docstr: Worker with a single policy and multiple environments.
  
  Alternates between taking a single step in all environments and asking the
  policy for an action for every environment. This allows computing a batch
  of actions, which is generally much more efficient than computing a single
  action when using neural networks.
  
  Args:
      seed (int): The seed to use to intialize random number generators.
      max_episode_length (int or float): The maximum length of episodes which
          will be sampled. Can be (floating point) infinity.
      worker_number (int): The number of the worker this update is
          occurring in. This argument is used  set a different seed for
          each worker.
      n_envs (int): Number of environment copies to use.
class_docstr_tok: ["Worker","with","a","single","policy","and","multiple","environments",".","Alternates","between","taking","a","single","step","in","all","environments","and","asking","the","policy","for","an","action","for","every","environment",".","This","allows","computing","a","batch","of","actions",",","which","is","generally","much","more","efficient","than","computing","a","single","action","when","using","neural","networks",".","Args",":","seed","(","int",")",":","The","seed","to","use","to","intialize","random","number","generators",".","max_episode_length","(","int","or","float",")",":","The","maximum","length","of","episodes","which","will","be","sampled",".","Can","be","(","floating","point",")","infinity",".","worker_number","(","int",")",":","The","number","of","the","worker","this","update","is","occurring","in",".","This","argument","is","used","set","a","different","seed","for","each","worker",".","n_envs","(","int",")",":","Number","of","environment","copies","to","use","."]
code: def _gather_episode(self, episode_number, last_observation):
      assert (
          0
          < self._episode_lengths[episode_number]
          <= self._max_episode_length
      )
      env_infos = self._env_infos[episode_number]
      agent_infos = self._agent_infos[episode_number]
      episode_infos = self._episode_infos[episode_number]
      for k, v in env_infos.items():
          env_infos[k] = np.asarray(v)
      for k, v in agent_infos.items():
          agent_infos[k] = np.asarray(v)
      for k, v in episode_infos.items():
          episode_infos[k] = np.asarray(v)
      eps = EpisodeBatch(
          env_spec=self._envs[episode_number].spec,
          episode_infos=dict(episode_infos),
          observations=np.asarray(self._observations[episode_number]),
          last_observations=np.asarray([last_observation]),
          actions=np.asarray(self._actions[episode_number]),
          rewards=np.asarray(self._rewards[episode_number]),
          step_types=np.asarray(
              self._step_types[episode_number], dtype=StepType
          ),
          env_infos=dict(env_infos),
          agent_infos=dict(agent_infos),
          lengths=np.asarray(
              [self._episode_lengths[episode_number]], dtype="l"
          ),
      )
  
      self._completed_episodes.append(eps)
      self._observations[episode_number] = []
      self._actions[episode_number] = []
      self._rewards[episode_number] = []
      self._step_types[episode_number] = []
      self._episode_lengths[episode_number] = 0
      self._prev_obs[episode_number] = self._envs[
          episode_number
      ].reset()[0]
      self._env_infos[episode_number] = collections.defaultdict(list)
      self._agent_infos[episode_number] = collections.defaultdict(list)
      self._episode_infos[episode_number] = collections.defaultdict(
          list
      )
  
file_path: garage/src/garage/sampler/vec_worker.py
imports: import collections
  import copy
  import numpy
  from garage import EpisodeBatch, StepType
  from garage.sampler import _apply_env_update
  from garage.sampler.default_worker import DefaultWorker
label_desc: Use image node_id 5 for calling the VecWorker obj's underlying member method code with example usage: obj._gather_episode(episode_number, last_observation) without return types