0
0
NumPydata~20 mins

Why saving and loading matters in NumPy - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Saving and Loading 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 this NumPy save and load code?
Consider this code that saves and loads a NumPy array. What will be printed?
NumPy
import numpy as np
arr = np.array([1, 2, 3])
np.save('temp.npy', arr)
loaded_arr = np.load('temp.npy')
print(loaded_arr)
AError: File not found
B[[1 2 3]]
C[1, 2, 3]
D[1 2 3]
Attempts:
2 left
💡 Hint
Remember that np.save saves the array in binary format and np.load loads it back as the same shape.
data_output
intermediate
2:00remaining
How many elements are in the loaded array?
This code saves a 2D array and loads it back. How many elements does the loaded array have?
NumPy
import numpy as np
arr = np.array([[1, 2], [3, 4], [5, 6]])
np.save('temp.npy', arr)
loaded_arr = np.load('temp.npy')
print(loaded_arr.size)
A6
B3
CError: AttributeError
D2
Attempts:
2 left
💡 Hint
The size attribute gives total number of elements in the array.
🔧 Debug
advanced
2:00remaining
What error does this code raise when loading a non-existent file?
What error will this code produce?
NumPy
import numpy as np
loaded_arr = np.load('missing_file.npy')
AValueError
BFileNotFoundError
CTypeError
DNo error, returns None
Attempts:
2 left
💡 Hint
Think about what happens if you try to open a file that does not exist.
🧠 Conceptual
advanced
2:00remaining
Why is saving and loading data important in data science?
Which of these is NOT a reason why saving and loading data matters?
ATo avoid repeating expensive computations
BTo share data easily between programs or people
CTo permanently delete data from memory
DTo preserve data state for future use
Attempts:
2 left
💡 Hint
Saving and loading helps keep data, not delete it.
🚀 Application
expert
3:00remaining
Which option correctly saves and loads a dictionary using NumPy?
You want to save a Python dictionary with NumPy and load it back. Which code works correctly?
Anp.save('dict.npy', my_dict); loaded = np.load('dict.npy', allow_pickle=True).item()
Bnp.save('dict.npy', my_dict); loaded = np.load('dict.npy')
Cnp.save('dict.npy', list(my_dict.items())); loaded = dict(np.load('dict.npy'))
Dnp.save('dict.npy', my_dict); loaded = np.load('dict.npy', allow_pickle=False)
Attempts:
2 left
💡 Hint
Dictionaries require pickling to save with NumPy.