【问题标题】:Error when loading .mat file with scipy.io (ValueError: Mat 4 mopt wrong format)使用 scipy.io 加载 .mat 文件时出错(ValueError:Mat 4 mopt 格式错误)
【发布时间】:2016-10-27 17:51:03
【问题描述】:

我目前正在尝试使用 scipy 和以下代码在 python 中加载 .mat 文件:

from scipy import io as sio
data= "file.mat"
output= sio.loadmat(data)

但是在运行命令时出现错误:

ValueError: Mat 4 mopt wrong format, byteswapping problem?

这个错误信息是什么意思?我尝试加载的文件有问题吗? 在编程方面我是个新手,所以任何建议都将不胜感激:) 如果有更好的方法在 python 中加载 .mat 文件,我也愿意听到这些。提前致谢!

【问题讨论】:

  • @hpaulj 感谢您的回复,我发现这些文件是 7.3 MAT 文件,HDF5 文件类型,因此 SciPy 不支持它们,可能会尝试使用 h5py 代替
  • 我将添加几个标签,这样更容易找到。随着 7.3 变得越来越普遍,我们会看到越来越多的此类错误。

标签: matlab scipy h5py


【解决方案1】:

我以前从未见过此错误,但它是由 scipy/scipy/io/matlab/mio4.py 中的第 113 行产生的

def read_header(self):
    ''' Read and return header for variable '''
    data = read_dtype(self.mat_stream, self.dtypes['header'])
    name = self.mat_stream.read(int(data['namlen'])).strip(b'\x00')
    if data['mopt'] < 0 or data['mopt'] > 5000:
        raise ValueError('Mat 4 mopt wrong format, byteswapping problem?')
    ...

通常loadmat 是正确的文件加载器,至少在支持的类型中:

支持 v4(1.0 级)、v6 和 v7 到 7.2 的 matfile。

你知道这个文件是如何保存在 MATLAB 中的吗?有没有像这样的格式规范?

【讨论】:

    猜你喜欢
    • 2021-12-14
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 2020-02-12
    • 2015-01-09
    • 2011-04-29
    相关资源
    最近更新 更多