0
0
NumPydata~20 mins

np.save() and np.load() for binary in NumPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Binary Save & Load Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of loading a saved NumPy array?
Consider the following code that saves and loads a NumPy array using np.save() and np.load(). What will be printed?
NumPy
import numpy as np
arr = np.array([10, 20, 30])
np.save('test_array.npy', arr)
loaded_arr = np.load('test_array.npy')
print(loaded_arr)
A[10, 20, 30]
B[[10 20 30]]
C[10 20 30]
DError: File not found
Attempts:
2 left
💡 Hint
Remember that np.save() stores the array in binary format and np.load() restores it exactly.
data_output
intermediate
1:30remaining
How many elements are in the loaded array?
Given the code below, how many elements does the loaded array contain?
NumPy
import numpy as np
arr = np.arange(12).reshape(3,4)
np.save('matrix.npy', arr)
loaded = np.load('matrix.npy')
print(loaded.size)
A3
BError: AttributeError
C4
D12
Attempts:
2 left
💡 Hint
The size attribute returns the total number of elements in the array.
🔧 Debug
advanced
1:00remaining
What error occurs when loading a non-existent file with np.load()?
What error will this code raise?
NumPy
import numpy as np
loaded = np.load('missing_file.npy')
AFileNotFoundError
BTypeError
CValueError
DSyntaxError
Attempts:
2 left
💡 Hint
Think about what happens when you try to open a file that does not exist.
🧠 Conceptual
advanced
1:30remaining
Which option correctly describes the file format used by np.save()?
What type of file does np.save() create when saving an array?
AA binary file in NumPy's .npy format
BA text file with comma-separated values
CA JSON file with array data
DAn XML file describing the array
Attempts:
2 left
💡 Hint
The file is designed for fast loading and saving of NumPy arrays.
🚀 Application
expert
2:00remaining
What is the shape of the loaded array after saving and loading a 3D array?
Given the code below, what will be the shape of the loaded array?
NumPy
import numpy as np
arr = np.ones((2,3,4))
np.save('3d_array.npy', arr)
loaded_arr = np.load('3d_array.npy')
print(loaded_arr.shape)
A(3, 4, 2)
B(2, 3, 4)
C(24,)
D(2, 12)
Attempts:
2 left
💡 Hint
The shape of the array is preserved exactly when saved and loaded with np.save and np.load.