Challenge - 5 Problems
Reshape Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of reshaping a 1D array to 2D
What is the output of this code?
import numpy as np arr = np.array([1, 2, 3, 4, 5, 6]) reshaped = arr.reshape(2, 3) print(reshaped)
NumPy
import numpy as np arr = np.array([1, 2, 3, 4, 5, 6]) reshaped = arr.reshape(2, 3) print(reshaped)
Attempts:
2 left
💡 Hint
Remember reshape changes the shape but keeps all elements in order.
✗ Incorrect
The array of 6 elements is reshaped into 2 rows and 3 columns, filling rows first.
❓ data_output
intermediate2:00remaining
Shape after reshaping with -1
Given this code, what is the shape of the reshaped array?
import numpy as np arr = np.arange(12) reshaped = arr.reshape(3, -1) print(reshaped.shape)
NumPy
import numpy as np arr = np.arange(12) reshaped = arr.reshape(3, -1) print(reshaped.shape)
Attempts:
2 left
💡 Hint
The -1 lets numpy calculate the missing dimension automatically.
✗ Incorrect
The array has 12 elements. Reshaping to 3 rows means columns = 12/3 = 4.
🔧 Debug
advanced2:00remaining
Error when reshaping incompatible size
What error does this code raise?
import numpy as np arr = np.arange(10) reshaped = arr.reshape(3, 4)
NumPy
import numpy as np arr = np.arange(10) reshaped = arr.reshape(3, 4)
Attempts:
2 left
💡 Hint
Check if total elements match new shape size.
✗ Incorrect
The original array has 10 elements but 3x4=12 elements are needed, so reshape fails.
🚀 Application
advanced2:00remaining
Reshape for image data
You have a flat array of 3072 elements representing a 32x32 RGB image (3 color channels). Which reshape call correctly converts it to (32, 32, 3)?
Attempts:
2 left
💡 Hint
Think about height, width, and color channels order.
✗ Incorrect
The image shape is height x width x channels, so (32, 32, 3) is correct.
🧠 Conceptual
expert2:00remaining
Effect of reshape on data order
When reshaping a numpy array, which statement is true about the order of elements in memory?
Attempts:
2 left
💡 Hint
Think about whether reshape rearranges data or just views it differently.
✗ Incorrect
Reshape only changes the shape metadata; the element order in memory stays the same.