Created
November 24, 2018 12:29
-
-
Save vihar/971cfaa94b882ecb32b84defca81ab3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
frames.append({ | |
'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): | |
clear_output(wait=True) | |
print(frame['frame'].getvalue()) | |
print(f"Timestep: {i + 1}") | |
print(f"State: {frame['state']}") | |
print(f"Action: {frame['action']}") | |
print(f"Reward: {frame['reward']}") | |
sleep(.1) | |
frames(frames) |
Thanks for the Article but I got an error :
TypeError: 'function' object is not iterable
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.
subsr97 - You must add in line 3 of your code
from IPython.display import clear_output
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!
print(frame['frame'].getvalue())
AttributeError: 'str' object has no attribute 'getvalue'
print(frame['frame'])
should work
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, your article is nice. I try to follow it but get error. what is the code for clear_output function ? Thanks