1. What do all elements of a NumPy array share?
- A Python object type per element
- A single value
- A single dtype
- Nothing in particular
Show answer
Answer: A single dtype
One dtype enables fast, compact storage.
Lesson: Creating and Shaping Arrays
25 questions from the NumPy / Pandas / scikit-learn course, each with the correct answer and an explanation. Try to answer before you open the answer.
Answer: A single dtype
One dtype enables fast, compact storage.
Lesson: Creating and Shaping Arrays
Answer: Yes, the (3,) array is broadcast across each row
Trailing dimensions match.
Answer: A basic slice such as a[1:4]
Slices are views; masks and lists copy.
Answer: The mean of each exam (column)
axis=0 collapses rows.
Lesson: Aggregation and Random Numbers
Answer: nan
NaN spreads; use np.nanmean to ignore it.
Lesson: Floating Point, Overflow and NaN
Answer: They add the numbers in a different order, and floating-point addition is not exactly associative
Compare floats with a tolerance.
Lesson: Vectorisation Instead of Loops
Answer: Its own dtype
Columns are typed Series.
Lesson: Series and DataFrames
Answer: iloc
i for integer position.
Lesson: Selecting Rows and Columns
Answer: NaN
Missing values become NaN.
Lesson: Reading and Writing Data
Answer: Drops every row that has any missing value
Often too aggressive; use subset.
Lesson: Handling Missing Values
Answer: Turns unparseable values into NaN
Bad values become missing.
Lesson: Types, Strings and Categories
Answer: df.loc[df["a"] > 1, "b"] = 0
One loc call on the original.
Lesson: Copy-on-Write in pandas 3
Answer: transform
Same length as the input.
Lesson: Grouping and Aggregating
Answer: A left join from orders
Left keeps all left rows.
Lesson: Merging and Concatenating
Answer: They are combined with the aggregation function
pivot_table aggregates; pivot would fail.
Lesson: Pivot Tables and Reshaping
Answer: Aggregates into weeks ending on Sunday
Weekly bins, W-SUN.
Lesson: Working With Time Series
Answer: To keep class proportions the same in train and test sets
Stratification preserves class balance.
Lesson: The Estimator API
Answer: Recall
Recall = found positives / all positives.
Lesson: Classification Metrics
Answer: The model is no better than predicting the mean
R² compares to the mean baseline.
Lesson: Regression and Baselines
Answer: Encodes unseen categories as all zeros instead of raising an error
Robust to new categories.
Lesson: Pipelines and ColumnTransformer
Answer: TimeSeriesSplit
Never train on the future.
Lesson: Cross-Validation
Answer: svc__C
step__parameter.
Lesson: Hyperparameter Search
Answer: Put them in a Pipeline so they are fitted only on training folds
Fit preprocessing on training data only.
Lesson: Data Leakage
Answer: Unpickling can execute arbitrary code
Pickle is not a safe format for untrusted input.
Lesson: Saving and Loading Models
Answer: Compare the model to a dummy baseline
A baseline shows whether the model adds value.