0
0
NumPydata~10 mins

Why saving and loading 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 save a NumPy array to a file.

NumPy
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
np.save('my_array.npy', [1])
Drag options to blanks, or click blank then click option'
Aarray
Barr
Cnp.array
Dmy_array
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the wrong variable name.
Trying to save the function instead of the array.
2fill in blank
medium

Complete the code to load a saved NumPy array from a file.

NumPy
import numpy as np
loaded_arr = np.[1]('my_array.npy')
Drag options to blanks, or click blank then click option'
Aload
Bsave
Cread
Dopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.save instead of np.load.
Using file open functions instead of NumPy's load.
3fill in blank
hard

Fix the error in the code to correctly save a NumPy array.

NumPy
import numpy as np
arr = np.array([10, 20, 30])
np.save('data.npy', [1])
Drag options to blanks, or click blank then click option'
Aarray
Bnp.array
Carr
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function np.array instead of the variable.
Passing a variable that does not exist.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that saves lengths of words longer than 3 characters.

NumPy
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Using the word itself instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that saves uppercase words with length greater than 3.

NumPy
words = ['apple', 'bat', 'carrot', 'dog']
result = { [1]: [2] for word in words if len(word) [3] 3 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Bword
C>
Dlen(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping keys and values.
Using wrong comparison operator.
Not converting words to uppercase.