An action space defines the actions an agent may choose while interacting with an environment. In Gym examples, its size is read from env.action_space.n and becomes the action dimension used by both tabular and neural agents. Each interaction selects one valid action, passes it to env.step(action), and receives the resulting state, reward, and completion signal. section 11.1.1 section 11.5
For FrozenLake, the action count determines the width of the Q-table: rows represent states and columns represent available actions. A Q-learning policy can either explore by sampling env.action_space or exploit by selecting the action with the largest Q value for the current state. Epsilon controls how often random selection is used, then decays as training proceeds. section 11.1.1
Several Gym environments use continuous state spaces with discrete action spaces. Their relative complexity is presented as the state-space size raised to the action-space size; for a mountain-car example with state space 2 and action space 3, the calculation is 2³ = 8. Larger or more complex settings motivate replacing a Q-table with a neural-network-based deep Q-learning approach. section 11.2
Connecting an action space to a DQN output
A DQN agent saves state_size and action_size when it is created. Its model accepts the state representation as input and ends with a linear layer containing action_size outputs. During action selection, the agent either returns a random integer below action_size for exploration or predicts output values and chooses the index with the maximum value. section 11.5
Use an action space in an executable Gym workflow:
- Create an environment and inspect env.action_space alongside its observation space. section 11.1.1 section 11.2
- Sample a random valid action to visualize or baseline an agent’s behavior. section 11.2
- Match the learning representation to the action count: Q-table columns for tabular learning or model outputs for DQN. section 11.1.1 section 11.5
- Try another environment and compare its action and observation/state spaces before running a random agent. section 11.2.1
Compare the displayed Gym environments by action-space and state-space sizes, then use those sizes to inspect the stated relative-complexity measure. section 11.2

