class_docstr: gym.Env wrapper to stack multiple frames.
  
  Useful for training feed-forward agents on dynamic games.
  Only works with gym.spaces.Box environment with 2D single channel frames.
  
  Args:
      env (gym.Env): gym.Env to wrap.
      n_frames (int): number of frames to stack.
      axis (int): Axis to stack frames on. This should be 2 for tensorflow
          and 0 for pytorch.
  
  Raises:
       ValueError: If observation space shape is not 2 dimnesional,
       if the environment is not gym.spaces.Box, or if the specified axis
       is not 0 or 2.
class_docstr_tok: ["gym.Env","wrapper","to","stack","multiple","frames",".","Useful","for","training","feed-forward","agents","on","dynamic","games",".","Only","works","with","gym.spaces.Box","environment","with","2D","single","channel","frames",".","Args",":","env","(","gym.Env",")",":","gym.Env","to","wrap",".","n_frames","(","int",")",":","number","of","frames","to","stack",".","axis","(","int",")",":","Axis","to","stack","frames","on",".","This","should","be","2","for","tensorflow","and","0","for","pytorch",".","Raises",":","ValueError",":","If","observation","space","shape","is","not","2","dimnesional",",","if","the","environment","is","not","gym.spaces.Box",",","or","if","the","specified","axis","is","not","0","or","2","."]
code: def __init__(self, env, n_frames, axis=2):
      if axis not in (0, 2):
          raise ValueError(
              "Frame stacking axis should be 0 for pytorch or "
              "2 for tensorflow."
          )
      if not isinstance(env.observation_space, gym.spaces.Box):
          raise ValueError(
              "Stack frames only works with gym.spaces.Box "
              "environment."
          )
  
      if len(env.observation_space.shape) != 2:
          raise ValueError(
              "Stack frames only works with 2D single channel images"
          )
  
      super().__init__(env)
  
      self._n_frames = n_frames
      self._axis = axis
      self._frames = deque(maxlen=n_frames)
  
      new_obs_space_shape = env.observation_space.shape + (n_frames,)
      if axis == 0:
          new_obs_space_shape = (
              n_frames,
          ) + env.observation_space.shape
  
      _low = env.observation_space.low.flatten()[0]
      _high = env.observation_space.high.flatten()[0]
      self._observation_space = gym.spaces.Box(
          _low,
          _high,
          shape=new_obs_space_shape,
          dtype=env.observation_space.dtype,
      )
  
file_path: garage/src/garage/envs/wrappers/stack_frames.py
imports: from collections import deque
  import gym
  import gym.spaces
  import numpy
label_desc: Use image node_id 1 to create a new StackFrames object from inherited base classes: gym with example: obj = StackFrames(env, n_frames, axis)