📘 Study Guide: 2D Arrays in
Python
With Real-World Applications &
Practice Solutions
1. What is a 2D Array?
• ▪ A 2D array is a list of lists in Python.
• ▪ Think of it like a table with rows and
columns.
• Example:
• matrix = [
• [1, 2, 3],
• [4, 5, 6],
• [7, 8, 9]
2. Accessing Elements
• ▪ Use row and column indexes.
• Example:
• print(matrix[0][1]) → 2
• print(matrix[2][0]) → 7
3. Traversing a 2D Array
• Row by row:
• for row in matrix:
• print(row)
• Element by element:
• for row in matrix:
• for element in row:
• print(element)
4. Common Operations
• ▪ Sum of all elements
• ▪ Sum of each row
• ▪ Sum of each column
• ▪ Finding largest element
5. Real-World Applications
• ▪ Student Marksheets (rows=students,
cols=subjects)
• ▪ Tic-Tac-Toe Game (3x3 grid)
• ▪ Images (pixels stored as numbers)
• ▪ Seating Charts (cinema, classrooms)
• ▪ Maps & GPS (cells represent locations)
6. Practice Tasks
• 1. Create a 3x3 matrix and print diagonal
elements.
• 2. Find the largest element in a 2D array.
• 3. Store marks of 4 students in 3 subjects and
find:
• ▪ Average marks of each student
• ▪ Highest marks in each subject
• 4. Create a 5x5 matrix with random numbers
and count even/odd.