Comprehensive assignment pack for NumPy Special
This assignment pack is layered. It starts with simple array creation and ends with expert-style numeric thinking, including broadcasting, aggregation, matrix work, timing comparison, and a mini project that feels close to real AI-ML preparation.
How to use this pack
- Students should attempt levels in order.
- Each level increases conceptual depth, not only code length.
- Encourage written explanation with every solution.
- Students should show outputs, not only paste code.
Submission rule
- One file or notebook per student.
- Every answer should include code, output, and a short explanation.
- At Levels 4 and 5, students must write what pattern they observed.
- Bonus marks for elegant vectorized solutions.
Level 1 — Ground zero
- Create a NumPy array containing numbers from 1 to 20.
- Print only even numbers.
- Print the first 5 elements, last 5 elements, and every second element.
- Write one sentence: how is this different from using a Python list?
Level 2 — Basic control of arrays
- Create a 3 × 4 matrix with values from 1 to 12.
- Print the shape, size, and number of dimensions.
- Print the second row and third column.
- Reshape the same values into a 2 × 6 matrix.
- Explain why reshape works here.
Level 3 — Vectorization and aggregation
- Create an array of marks for 10 students.
- Add 5 grace marks to all students using vectorized code.
- Find total, average, highest, lowest, median, and standard deviation.
- Count how many students scored above the class average.
- Sort the marks in ascending order.
Level 4 — Broadcasting and axis work
- Create a 4 × 3 matrix representing 4 students and 3 subjects.
- Find row sums and column sums.
-
Add subject-wise bonus marks using broadcasting, for example
[2, 5, 3]. - Find each student’s maximum score.
- Find the average score in each subject.
-
Explain what
axis=0andaxis=1mean in your own words.
Level 5 — Expert point 100
-
Create a random dataset of 50 student marks using
np.random.randint(30, 100, 50). - Reshape it into a 10 × 5 matrix.
- Interpret rows as students and columns as tests.
- Find each student’s total and average.
- Find the topper based on total marks.
- Find how many test scores are below 40.
- Create a 10 × 10 random integer matrix and normalize it by dividing by 100.
- Write 5–8 lines explaining how these kinds of operations prepare data for AI-ML.
Challenge tasks
- Compare list addition and array addition with your own example.
-
Create a timing comparison using Python
timeortimeitfor loop style versus vectorized style. - Transpose a matrix and describe what changed.
- Show one reshape attempt that fails and explain why it fails.
Mini project
Build a Student Dataset Analyzer. The program should create or accept marks, summarize them, reshape them into a readable matrix, identify topper and below-average students, and print a final interpretation paragraph.
import numpy as np
marks = np.random.randint(35, 100, 20)
print("Marks:", marks)
print("Average:", np.mean(marks))
print("Top score:", np.max(marks))
print("Below average:", np.sum(marks < np.mean(marks)))
Evaluation rubric
| Criterion | Marks focus | What strong work looks like |
|---|---|---|
| Correctness | 25 | Code runs and gives correct outputs |
| Concept understanding | 25 | Student can explain shape, slicing, vectorization, and broadcasting clearly |
| Clean coding | 15 | Readable code, sensible variable names, useful comments |
| Interpretation | 20 | Student explains what the results mean, not only what they are |
| Depth / challenge attempt | 15 | Student goes beyond minimum and attempts higher-level tasks |