0
0
SciPydata~10 mins

Saving and loading data (scipy.io) - 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 a NumPy array to a .mat file using scipy.io.

SciPy
import numpy as np
from scipy import io
arr = np.array([1, 2, 3])
io.[1]('data.mat', {'arr': arr})
Drag options to blanks, or click blank then click option'
Asavemat
Bload
Csave
Dloadmat
Attempts:
3 left
💡 Hint
Common Mistakes
Using loadmat instead of savemat to save data.
Using save or load which are not scipy.io functions.
2fill in blank
medium

Complete the code to load data from a .mat file using scipy.io.

SciPy
from scipy import io
data = io.[1]('data.mat')
print(data['arr'])
Drag options to blanks, or click blank then click option'
Aload
Bsavemat
Cloadmat
Dsave
Attempts:
3 left
💡 Hint
Common Mistakes
Using savemat instead of loadmat to load data.
Using save or load which are not scipy.io functions.
3fill in blank
hard

Fix the error in the code to correctly save two arrays to a .mat file.

SciPy
import numpy as np
from scipy import io
x = np.array([1, 2])
y = np.array([3, 4])
io.savemat('data.mat', [1])
Drag options to blanks, or click blank then click option'
A{'x': x, 'y': y}
B[x, y]
Cx, y
D('x', x, 'y', y)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list or tuple instead of a dictionary.
Passing variables without keys.
4fill in blank
hard

Fill both blanks to save a dictionary with arrays and then load it back.

SciPy
from scipy import io
import numpy as np
data = {'a': np.array([1, 2]), 'b': np.array([3, 4])}
io.[1]('file.mat', data)
loaded = io.[2]('file.mat')
print(loaded['a'])
Drag options to blanks, or click blank then click option'
Asavemat
Bloadmat
Csave
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up savemat and loadmat.
Using save or load which are not scipy.io functions.
5fill in blank
hard

Fill all three blanks to save an array with a custom name, load it, and print the loaded array.

SciPy
import numpy as np
from scipy import io
arr = np.array([10, 20, 30])
io.[1]('mydata.mat', [2])
loaded = io.[3]('mydata.mat')
print(loaded['my_array'])
Drag options to blanks, or click blank then click option'
Asavemat
B{'my_array': arr}
Cloadmat
D{'array': arr}
Attempts:
3 left
💡 Hint
Common Mistakes
Not using a dictionary with the correct key name.
Using wrong function names for saving or loading.