Challenge - 5 Problems
Binary Save & Load Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
Remember that
np.save() stores the array in binary format and np.load() restores it exactly.✗ Incorrect
The
np.save() function saves the array in a binary file. When loaded back with np.load(), it returns the original array with the same shape and values. Printing the array shows it without commas as in option C.❓ data_output
intermediate1: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)
Attempts:
2 left
💡 Hint
The
size attribute returns the total number of elements in the array.✗ Incorrect
The original array has shape (3,4), so total elements = 3 * 4 = 12. The loaded array keeps the same shape and size.
🔧 Debug
advanced1: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')
Attempts:
2 left
💡 Hint
Think about what happens when you try to open a file that does not exist.
✗ Incorrect
Trying to load a file that does not exist raises a
FileNotFoundError in Python.🧠 Conceptual
advanced1:30remaining
Which option correctly describes the file format used by np.save()?
What type of file does
np.save() create when saving an array?Attempts:
2 left
💡 Hint
The file is designed for fast loading and saving of NumPy arrays.
✗ Incorrect
np.save() writes the array to a binary file with the .npy extension, which stores metadata and data efficiently.🚀 Application
expert2: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)
Attempts:
2 left
💡 Hint
The shape of the array is preserved exactly when saved and loaded with np.save and np.load.
✗ Incorrect
The original array has shape (2, 3, 4). Saving and loading with np.save and np.load keeps the shape unchanged.