SciPy Matlab Arrays
Learn all about SciPy Matlab Arrays in this comprehensive tutorial.
- •We know that NumPy provides us with methods to persist the data in readable formats for Python.
- •The savemat() function allows us to export data in Matlab format.
- •The loadmat() function allows us to import data from a Matlab file.
Working With Matlab Arrays
We know that NumPy provides us with methods to persist the data in readable formats for Python. But SciPy provides us with interoperability with Matlab as well.
SciPy provides us with the module scipy.io, which has functions for working with Matlab arrays.
Exporting Data in Matlab Format
The savemat() function allows us to export data in Matlab format.
The method takes the following parameters:
- **filename** - the file name for saving data.
- **mdict** - a dictionary containing the data.
- **do_compression** - a boolean value that specifies whether to compress the result or not. Default False.
Import Data from Matlab Format
The loadmat() function allows us to import data from a Matlab file.
The function takes one required parameter:
filename - the file name of the saved data.
It will return a structured array whose keys are the variable names, and the corresponding values are the variable values.
Use the variable name "vec" to display only the array from the matlab data:
Note: We can see that the array originally was 1D, but on extraction it has increased one dimension.
In order to resolve this we can pass an additional argument squeeze_me=True:
Module quiz
2 questionsWhich of the following is true about SciPy Matlab Arrays?
What is the most common pitfall when working with SciPy Matlab Arrays?
Answer all questions to submit.