如何加载* .mat文件并将其转换为numpy数组?

时间:2015-03-25 15:31:05

标签: python matlab numpy scipy

与主题一样,即。如何加载给定的*.mat文件并将其转换为numpy数组?说,我有一个matlab矩阵:

X =

     8     1     6
     3     5     7
     4     9     2

我将其保存为data.mat,现在我想在我的python脚本中加载它,接下来我要将其转换为numpy数组,因此它将变为:

np.array([[8, 1, 6], [3, 5, 7], [4, 9, 2]])

我已经知道,我可以使用scipy.io.loadmat()函数,但当我尝试这样调用它时:

mat = scipy.io.loadmat('data')

...我收到了错误:

Traceback (most recent call last):
  File "C:/Users/jsmith/PycharmProjects/MagicScript.py", line 4, in <module>
    mat = si.loadmat('data')
  File "C:\Users\jsmith\Anaconda3\lib\site-packages\scipy\io\matlab\mio.py", line 131, in loadmat
    MR = mat_reader_factory(file_name, appendmat, **kwargs)
  File "C:\Users\jsmith\Anaconda3\lib\site-packages\scipy\io\matlab\mio.py", line 55, in mat_reader_factory
    mjv, mnv = get_matfile_version(byte_stream)
  File "C:\Users\jsmith\Anaconda3\lib\site-packages\scipy\io\matlab\miobase.py", line 237, in get_matfile_version
    % ret)
ValueError: Unknown mat file type, version 46, 51

提前谢谢。

0 个答案:

没有答案