#Error on Cart Pole project V1

1 messages · Page 1 of 1 (latest)

wooden sun
#

There's an issue where I was just coding when it inputs this error:

TypeError: Dimension value must be integer or None or have an index method, got value '(array([ 0.03218328, -0.01547841, 0.03699298, -0.01503247], dtype=float32), {})' with type '<class 'tuple'>'

umbral heath
wooden sun
#

Hello there here's the full code:

env = gym.make("CartPole-v1", render_mode="human")
states = env.observation_space.shape[0]
actions = env.action_space.n

episodes = 10
for episode in range(1, episodes+1):
states = env.reset()
done = False
score = 0

while not done:
    env.render()
    action = random.choice([0, 1])
    n_state, reward, done, info, _ = env.step(action)
    score+=reward
print("Episode:{} Score:{}".format(episode,score))

def build_model(states, actions):
model = Sequential()
model.add(Flatten(input_shape=(states,)))
model.add(Dense(24, activation="relu"))
model.add(Dense(24, activation="relu"))
model.add(Dense(actions, activation="linear"))
return model

model = build_model(states, actions)

Here when I run the model, it prints out that specific error

umbral heath
wooden sun
#

oh sorry my bad if it's not related, because I thought the gym documentation has some correlation with openai

umbral heath
wooden sun