Skip to content

Instantly share code, notes, and snippets.

Created November 24, 2018 12:29
Show Gist options
  • Save vihar/971cfaa94b882ecb32b84defca81ab3e to your computer and use it in GitHub Desktop.
Save vihar/971cfaa94b882ecb32b84defca81ab3e to your computer and use it in GitHub Desktop.
import gym
from time import sleep
# Creating thr env
env = gym.make("Taxi-v2").env
env.s = 328
# Setting the number of iterations, penalties and reward to zero,
epochs = 0
penalties, reward = 0, 0
frames = []
done = False
while not done:
action = env.action_space.sample()
state, reward, done, info = env.step(action)
if reward == -10:
penalties += 1
# Put each rendered frame into the dictionary for animation
'frame': env.render(mode='ansi'),
'state': state,
'action': action,
'reward': reward
epochs += 1
print("Timesteps taken: {}".format(epochs))
print("Penalties incurred: {}".format(penalties))
# Printing all the possible actions, states, rewards.
def frames(frames):
for i, frame in enumerate(frames):
print(f"Timestep: {i + 1}")
print(f"State: {frame['state']}")
print(f"Action: {frame['action']}")
print(f"Reward: {frame['reward']}")
Copy link

techwm commented Dec 8, 2018

Hi, your article is nice. I try to follow it but get error. what is the code for clear_output function ? Thanks

Copy link

Thanks for the Article but I got an error :
TypeError: 'function' object is not iterable

Copy link

subsr97 commented Dec 25, 2018

TypeError: 'function' object is not iterable
Change the function name from frames to renderFrames in line 40 and 50.

name 'clear_output' is not defined
Use from IPython.display import clear_output if you're using Jupyter notebook.

Copy link

clebrw commented Mar 5, 2019

subsr97 - You must add in line 3 of your code
from IPython.display import clear_output

Copy link

Looks like Author has not defined the Solution on How to resolve the TypeError: function object is not iterable.
If message thread is Open then please provide the response on the Error Resolution. Appreciation in advance!

Copy link

AttributeError: 'str' object has no attribute 'getvalue'

Copy link

should work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment