Implementing Q-Table in Python
A simple example of Q-learning.
1
Implementing Q-Learning in Python
In this lesson, we will implement a simple Q-Learning algorithm in Python. The agent will learn to navigate a grid world to maximize its rewards.

2
Defining the Environment
We define a simple 4×4 grid world where the agent starts at the top-left corner and must reach the bottom-right corner to receive a reward.
import numpy as np
# Define the environment
num_states = 16 # 4x4 grid
num_actions = 4 # Up, Down, Left, Right
# Define rewards (-1 for each step, +10 for the goal)
rewards = np.zeros(num_states)
rewards[-1] = 10All lessons in this course
- Basic Concepts in Reinforcement Learning
- Q-Table Concept
- Implementing Q-Table in Python
- Deep Q-Learning
- Exploring OpenAI Gym