0
0
SciPydata~10 mins

MATLAB file I/O (loadmat, savemat) in SciPy - Interactive Code Practice

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

Complete the code to load a MATLAB file named 'data.mat' into a Python variable.

SciPy
from scipy.io import [1]
data = [1]('data.mat')
Drag options to blanks, or click blank then click option'
Areadmat
Bsavemat
Cloadmat
Dloadtxt
Attempts:
3 left
💡 Hint
Common Mistakes
Using savemat instead of loadmat
Trying to use loadtxt which is for text files
2fill in blank
medium

Complete the code to save a Python dictionary 'my_data' to a MATLAB file named 'output.mat'.

SciPy
from scipy.io import [1]
my_data = {'a': [1, 2, 3]}
[1]('output.mat', my_data)
Drag options to blanks, or click blank then click option'
Aloadmat
Bdumpmat
Csave
Dsavemat
Attempts:
3 left
💡 Hint
Common Mistakes
Using loadmat instead of savemat
Using save which is not a scipy.io function
3fill in blank
hard

Fix the error in the code to correctly load a MATLAB file and access variable 'x'.

SciPy
from scipy.io import loadmat
data = loadmat('file.mat')
x = data[1]
Drag options to blanks, or click blank then click option'
A['x']
Bx
C.x
D['data']
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access variable as an attribute with dot notation
Using variable name without quotes or brackets
4fill in blank
hard

Fill both blanks to save a dictionary with variable 'y' to 'result.mat' and then load it back.

SciPy
from scipy.io import [1], [2]
data_to_save = {'y': [4, 5, 6]}
[1]('result.mat', data_to_save)
loaded_data = [2]('result.mat')
Drag options to blanks, or click blank then click option'
Asavemat
Bloadmat
Csave
Dreadmat
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up savemat and loadmat
Using non-existing functions like save or readmat
5fill in blank
hard

Fill all three blanks to load 'data.mat', extract variable 'z', and save it to 'new_data.mat'.

SciPy
from scipy.io import [1], [2]
data = [1]('data.mat')
z = data['z']
[2]('new_data.mat', {'z': z})
Drag options to blanks, or click blank then click option'
Aloadmat
Bsavemat
Cload
Dsave
Attempts:
3 left
💡 Hint
Common Mistakes
Using save or load which are not scipy.io functions
Not importing both functions before use