RqdMemez
RqdMemez

Reputation: 27

TypeError: 'numpy.int64' object is not iterable

Sorry I'm not that good at StackOverflow.

I'm trying to make a game bot with universe and i got an error saying:

[2018-09-14 07:28:33,723] Making new env: Taxi-v2
Traceback (most recent call last):
  File "d:\pacmantest.py", line 8, in <module>
    action_n = [[('KeyEvent', 'ArrowUp', True)] for ob in observation_n] 
TypeError: 'numpy.int64' object is not iterable

The code is:

import gym
import universe

env = gym.make('Taxi-v2')
observation_n = env.reset()

while True:
  action_n = [[('KeyEvent', 'ArrowUp', True)] for ob in observation_n] 
  observation_n, reward_n, done_n, info = env.step(action_n)
  env.render()

Upvotes: 1

Views: 8761

Answers (2)

Daneel R.
Daneel R.

Reputation: 547

If you execute print(type(observation_n)) immediately after observation_n = env.reset() it will likely print 'numpy.int64'. You can only iterate on iterable objects, such as lists, single values such as int64 are not iterable.

Upvotes: 1

blue note
blue note

Reputation: 29081

Switch the first two lines of your while loop. env.reset returns an int, while env.step returns a tuple.

Upvotes: 0

Related Questions