loading .mat and .m files with loadmat in Python

Viewed 24493

I am currently taking a Neural Network course, and I am trying to load a .mat file from Python using scipy.io.loadmat(filename), but I keep getting the following error message:

ValueError: Unknown mat file type, version 101, 58

The same message occured when I tried loading a .m file, rather than .mat file, using scipy.io.loadmat().

I don't know how to resolve this issue, so I would really appreciate if someone on here could help me out.

5 Answers

For people coming over this issue again. You can use numpy.loadtxt() to read .mat files generated by Octave.

For example. In Octave:

octave:1> arr1 = [1,2]
octave:2> arr2 = [2,3]
octave:3> save mydata.mat arr1 arr2

Then read mydata.mat in Python Interpreter:

>>> import numpy as np
>>> data = np.loadtxt('mydata.mat')
>>> data
array([[1., 2.],
       [2., 3.]])

Much easier is to just load your data with:

numpy.loadtxt('your dot mat file')
Related