Take a moment to think about this
In this project, we'll build a mini dashboard that stores and analyzes students' subject scores in a NumPy 2D array. You could write this with a Python list of lists too, but a NumPy array gives you the edge of checking the data structure instantly through attributes like shape and dtype, and later lets you handle aggregation and broadcasting without writing loops. In Part 1, we'll just build the core data structure — checking attributes (shape, ndim, dtype) and practicing indexing/slicing alongside the student list and subject list. This step is the base data for Part 2's analysis and Part 3's final report.
Let's build it
Manually enter a score array for 5 students and 4 subjects (Math, Myanmar, English, Science) with np.array as a 2D shape (5, 4). Keep separate Python lists for students and subjects so each index maps to a name. Print scores.shape, scores.ndim, and scores.dtype to confirm the data structure. Try scores[0] to get the first student's scores across all subjects, and scores[:, 1] to pull out the Myanmar subject column using slicing.
Example Code
import numpy as np
students = ["Aye", "Bo", "Cho", "Dan", "Eaint"]
subjects = ["Math", "Myanmar", "English", "Science"]
# rows = students, columns = subjects
scores = np.array([
[78, 85, 90, 72],
[64, 70, 58, 80],
[95, 88, 92, 91],
[50, 60, 55, 48],
[82, 79, 84, 88]
])
print("shape:", scores.shape)
print("ndim:", scores.ndim)
print("dtype:", scores.dtype)
# first student's all subject scores
print(students[0], "scores:", scores[0])
# every student's Myanmar (column index 1) score
print("Myanmar scores:", scores[:, 1])
You'll see shape (5, 4), ndim 2, and dtype int64 (or int32) printed out, along with the student list and subject slicing results showing the correct student/subject scores.Try it in 5 minutes
Add one more student and one more subject (History), and rewrite the scores array so it becomes shape (6, 5) (5 minutes).
A quick word of caution
When you create an array with np.array() from a nested list, every row needs to be the same length. If they're not, you'll end up with a shape of (5,) as an object array, and it'll throw errors later in aggregation and broadcasting.