I have written a function to convert a NumPy array into a mat file using scipy.io.savemat() but it produces a generic type of file: File with the same name but not of type .mat as expected. The array I want to save is of type <class ‘numpy.ndarray’> as verified by the print statement. I don’t know what may be the issue.
JavaScript
x
11
11
1
2
import os
3
import scipy.io
4
5
def save_electrode_measurement_to_matfile( measurement: np.ndarray, file_name: str = 'latest_electrode_measurement'):
6
print(type(measurement))
7
mdict = { 'electrode_measurement' : measurement}
8
dir = r"...Simulation_results"
9
file_path = os.path.join(dir, file_name)
10
scipy.io.savemat(file_path, mdict, appendmat = True)
11
Advertisement
Answer
Refering to the documentation, I think that you should add ‘.mat’ to the filename (which is the file_path in your case). By replacing
JavaScript
1
2
1
file_path = os.path.join(dir, file_name)
2
with
JavaScript
1
2
1
file_path = os.path.join(dir, file_name) + ".mat"
2
Your problem should be solved.