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 ?
Answers:
env.observation_space.shape
is a tuple not a list. Getting its value at index 0 returns the first element, which is 4.
(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
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
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/
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 ?
env.observation_space.shape
is a tuple not a list. Getting its value at index 0 returns the first element, which is 4.
(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
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
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/