0
0
NumPydata~10 mins

Why reshaping arrays matters in NumPy - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to reshape a 1D array into a 2D array with 3 rows.

NumPy
import numpy as np
arr = np.array([1, 2, 3, 4, 5, 6])
reshaped = arr.[1]((3, 2))
print(reshaped)
Drag options to blanks, or click blank then click option'
Areshape
Bresize
Cflatten
Dravel
Attempts:
3 left
💡 Hint
Common Mistakes
Using resize instead of reshape.
Using flatten which converts to 1D instead of reshaping.
2fill in blank
medium

Complete the code to reshape a 2D array into a 1D array.

NumPy
import numpy as np
arr = np.array([[1, 2], [3, 4], [5, 6]])
flat = arr.[1]()
print(flat)
Drag options to blanks, or click blank then click option'
Aexpand_dims
Breshape
Cresize
Dflatten
Attempts:
3 left
💡 Hint
Common Mistakes
Using reshape without specifying shape.
Using resize which modifies the original array.
3fill in blank
hard

Fix the error in reshaping an array with incompatible size.

NumPy
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
reshaped = arr.[1]((2, 3))
print(reshaped)
Drag options to blanks, or click blank then click option'
Aresize
Bflatten
Creshape
Dravel
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to reshape to a shape that doesn't match total elements.
Using resize which changes data and size.
4fill in blank
hard

Fill both blanks to create a dictionary with word lengths for words longer than 3 letters.

NumPy
words = ['data', 'science', 'is', 'fun']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of its length.
Using wrong comparison operator in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.

NumPy
data = {'a': 1, 'b': -2, 'c': 3}
result = { [1]: [2] for k, v in data.items() if v [3] 0 }
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using original keys without uppercase conversion.
Using wrong comparison operator or filtering condition.