Recall & Review
beginner
What does the
reshape() function do in NumPy?It changes the shape or dimensions of an existing array without changing its data.
Click to reveal answer
beginner
How do you reshape a 1D array of 6 elements into a 2D array with 2 rows and 3 columns?
Use
array.reshape(2, 3) where array is your original 1D array.Click to reveal answer
intermediate
What happens if you try to reshape an array into a shape that does not match the total number of elements?
NumPy will raise an error because the total number of elements must remain the same.
Click to reveal answer
intermediate
What does using
-1 in the reshape dimensions mean?It tells NumPy to automatically calculate that dimension based on the array size and other given dimensions.
Click to reveal answer
beginner
Can
reshape() change the total number of elements in the array?No,
reshape() only changes the shape, not the total number of elements.Click to reveal answer
What will
np.array([1,2,3,4,5,6]).reshape(3,2) produce?✗ Incorrect
The reshape changes the 1D array into 3 rows and 2 columns.
What does
reshape(-1, 1) do to a 1D array?✗ Incorrect
Using -1 lets NumPy calculate the number of rows, making it a column vector.
If an array has 12 elements, which reshape is invalid?
✗ Incorrect
5x3=15 which does not match 12 elements, so it is invalid.
What must remain the same before and after using reshape()?
✗ Incorrect
Reshape only changes dimensions, not the total number of elements.
Which of these is a valid way to reshape an array
arr with 8 elements?✗ Incorrect
2x4=8 matches the total elements, so it is valid.
Explain how the
reshape() function works in NumPy and why the total number of elements must stay the same.Think about how you can rearrange items in boxes without adding or removing items.
You got /4 concepts.
Describe how using
-1 in reshape helps when changing array dimensions.It’s like telling NumPy: 'You figure out this size for me.'
You got /4 concepts.