A. Error because NumPy arrays cannot be multiplied by 2
B. [2 4 6 8] and a DataFrame with doubled values in 'Numbers' column
C. Only the DataFrame doubles values; NumPy array stays the same
D. Both print statements produce the same string output
Solution
Step 1: Multiply NumPy array by 2
NumPy arrays support element-wise multiplication, so arr * 2 doubles each element.
Step 2: Multiply pandas DataFrame by 2
Pandas DataFrames also support element-wise multiplication, doubling values in the 'Numbers' column.
Final Answer:
[2 4 6 8] and a DataFrame with doubled values in 'Numbers' column -> Option B
Quick Check:
NumPy and pandas both double numeric data [OK]
Hint: NumPy and pandas multiply numeric data element-wise [OK]
Common Mistakes:
Expecting errors on multiplying arrays
Thinking only DataFrame supports multiplication
Confusing output formats of array vs DataFrame
4. Identify the error in this code when trying to use NumPy for labeled data:
import numpy as np
arr = np.array([1, 2, 3])
print(arr['index'])
medium
A. NumPy arrays do not support label-based indexing like 'index'
B. The array is missing a label definition
C. The syntax for accessing elements is incorrect; should use parentheses
D. NumPy arrays cannot contain integers
Solution
Step 1: Understand NumPy indexing
NumPy arrays use integer-based indexing, not labels like 'index'.
Step 2: Recognize label support in pandas
Only pandas DataFrames or Series support label-based indexing.
Final Answer:
NumPy arrays do not support label-based indexing like 'index' -> Option A
Quick Check:
NumPy = integer indexing only [OK]
Hint: NumPy uses integer indexes, not labels [OK]
Common Mistakes:
Trying to use labels with NumPy arrays
Confusing syntax for element access
Assuming NumPy supports DataFrame features
5. You have a large dataset of numeric sensor readings stored as a 3D array. You want to perform fast matrix operations and do not need row or column labels. Which approach is best?
hard
A. Use pandas DataFrame for easy labeling and indexing
B. Convert data to Python lists for flexibility
C. Use pandas Series for one-dimensional data handling
D. Use NumPy arrays for efficient multi-dimensional numeric computations
Solution
Step 1: Analyze data structure and needs
The data is a large 3D numeric array needing fast matrix operations without labels.
Step 2: Match tool to task
NumPy excels at multi-dimensional arrays and fast numeric computations without labels.
Step 3: Evaluate other options
Pandas is slower and designed for labeled 1D/2D data; Python lists are inefficient for math.
Final Answer:
Use NumPy arrays for efficient multi-dimensional numeric computations -> Option D
Quick Check:
NumPy = best for fast multi-dimensional math [OK]
Hint: Choose NumPy for fast multi-dimensional numeric data [OK]
Common Mistakes:
Using pandas for unlabeled multi-dimensional arrays
Choosing Python lists for numeric matrix math
Confusing Series with multi-dimensional data
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.