0
0
NumPydata~10 mins

np.save() and np.load() for binary in NumPy - Interactive Code Practice

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

Complete the code to save the numpy array to a binary file.

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

Complete the code to load the numpy array from the binary file.

NumPy
import numpy as np
loaded_arr = np.load([1])
print(loaded_arr)
Drag options to blanks, or click blank then click option'
A'data.npy'
Bdata.npy
C'arr.npy'
Darr.npy
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the filename.
Using the wrong filename.
3fill in blank
hard

Fix the error in the code to correctly save the array in binary format.

NumPy
import numpy as np
arr = np.array([5, 6, 7])
np.save('my_array.npy', [1])
Drag options to blanks, or click blank then click option'
Aarr.copy
Barr
Carr.tolist
Darr.mean
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses after the array variable.
Passing a method instead of the array.
4fill in blank
hard

Fill both blanks to save and then load the array correctly.

NumPy
import numpy as np
arr = np.array([10, 20, 30])
np.save([1], [2])
loaded = np.load('numbers.npy')
print(loaded)
Drag options to blanks, or click blank then click option'
A'numbers.npy'
Barr
C'arr.npy'
Dnumbers
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different filename in np.save() than in np.load().
Passing a string instead of the array variable as the second argument.
5fill in blank
hard

Fill all three blanks to save an array, load it, and print the first element.

NumPy
import numpy as np
arr = np.array([100, 200, 300])
np.save([1], [2])
loaded_arr = np.load([3])
print(loaded_arr[0])
Drag options to blanks, or click blank then click option'
A'values.npy'
Barr
D'data.npy'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different filenames for saving and loading.
Passing a string instead of the array variable when saving.