What's the different between these two results?

Question:

Here is my code:

import gym

env = gym.make("CartPole-v1")

print (env.observation_space.shape)
print (env.observation_space.shape[0])

The result is

(4,)
4

I don’t understand what’s the difference between (4,) and 4 ?

Asked By: GreenTea

||

Answers:

env.observation_space.shape is a tuple not a list. Getting its value at index 0 returns the first element, which is 4.

Answered By: new-dev-123

(4,) represents the shape of your observation space. The output is (‘row’,’column’).

print (env.observation_space.shape[0]) the [0] index shows the number of rows

Answered By: Aaron

Here’s the offical doc:http://gym.openai.com/docs/#spaces

UPDATE: https://www.gymlibrary.dev/

env.observation_space.shape is 1 dim tuple.

So, env.observation_space.shape returns (4,)

env.observation_space.shape[0] returns 4

Answered By: 此方一泉

In python, to create a tuple you must give it at least two numbers. If you only want a tuple with one then you need to still separate that number with a comma, as in (4,).

https://www.reddit.com/r/Python/comments/cf25sq/dont_understand_what_does_it_mean_4/

Answered By: GreenTea
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.