0
0
NumPydata~5 mins

reshape() for changing dimensions in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AA 1D array with 6 elements
BA 3x2 array with elements [[1,2],[3,4],[5,6]]
CAn error because the shape is invalid
DA 2x3 array with elements [[1,2,3],[4,5,6]]
What does reshape(-1, 1) do to a 1D array?
ARaises an error
BConverts it to a 2D row vector
CFlattens the array
DConverts it to a 2D column vector
If an array has 12 elements, which reshape is invalid?
Areshape(5,3)
Breshape(3,4)
Creshape(2,6)
Dreshape(4,3)
What must remain the same before and after using reshape()?
AThe data type
BThe shape of the array
CThe total number of elements
DThe memory address
Which of these is a valid way to reshape an array arr with 8 elements?
Aarr.reshape(2, 4)
Barr.reshape(3, 3)
Carr.reshape(4, 3)
Darr.reshape(5, 2)
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.