Indexing, Slicing, and Masks
Unit ID: M08-U03 Estimated active time: 25-35 minutes
Use [row, column] for one value, slices for ranges, and a Boolean mask for a rule.
first_learner_week_two = study_minutes[0, 1]
first_two_weeks = study_minutes[:, :2]
active_values = study_minutes[study_minutes >= 45]
The mask has the same shape as the source before selection. It records True where the rule passes.
active_mask = study_minutes >= 45
print(active_mask)
A mask that flattens selected values answers a different question from preserving rows. To keep only learners whose four-week total reaches 160 minutes, calculate row totals first and use that one-dimensional mask on rows.
Practice: select the third week, all values below 30, and rows with at least one zero. Explain the shape of each result.
