Challenge - 5 Problems
ndarray Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of ndarray shape and size
What is the output of the following code snippet?
NumPy
import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6]]) print(arr.shape, arr.size)
Attempts:
2 left
💡 Hint
Shape gives rows and columns, size is total elements.
✗ Incorrect
The array has 2 rows and 3 columns, so shape is (2, 3). Total elements are 6.
❓ data_output
intermediate2:00remaining
Result of ndarray slicing
What is the output of slicing the array below?
NumPy
import numpy as np arr = np.array([10, 20, 30, 40, 50]) print(arr[1:4])
Attempts:
2 left
💡 Hint
Slicing excludes the last index.
✗ Incorrect
Slicing from index 1 to 4 includes elements at positions 1, 2, and 3.
🔧 Debug
advanced2:00remaining
Identify the error in ndarray reshaping
What error does this code raise?
NumPy
import numpy as np arr = np.array([1, 2, 3, 4, 5]) arr.reshape(2, 3)
Attempts:
2 left
💡 Hint
Total elements must match new shape.
✗ Incorrect
The array has 5 elements but reshape tries to make shape (2,3) which needs 6 elements.
❓ visualization
advanced2:00remaining
Visualize the effect of ndarray transpose
What is the output of transposing this array?
NumPy
import numpy as np arr = np.array([[1, 2], [3, 4], [5, 6]]) print(arr.T)
Attempts:
2 left
💡 Hint
Transpose flips rows and columns.
✗ Incorrect
Original shape is (3,2), transpose shape is (2,3) with rows and columns swapped.
🧠 Conceptual
expert2:00remaining
Understanding ndarray broadcasting rules
Given arrays a with shape (3,1) and b with shape (1,4), what is the shape of a + b?
Attempts:
2 left
💡 Hint
Broadcasting matches dimensions by expanding singleton dimensions.
✗ Incorrect
Shapes (3,1) and (1,4) broadcast to (3,4) for element-wise addition.