学习笔记192—python中使用h5py 读取.mat文件时报错“Unable to open file (file signature not found)”

python中使用h5py 读取.mat文件时报错:Unable to open file (file signature not found)

python读取matlab的mat文件失败

遇到BUG:

h5py OSError: Unable to open file (File signature not found)

一般python读取mat文件的语句是scipy.io.laodmat()

但是这次需要用h5py.File()读取,一直显示读取失败

后来找到是matlab制作mat文件有问题,例如下面这句话:

save('data.mat', 'name', 'age')

从scipy.io.laodmat()可以正常读取,但是使用h5py.File()就不行,显示签名失败。后来读了一下matlab的源代码说明,最后面要加一个version参数,该参数可以是‘-v4’,‘-v5’,‘-v6’,‘-v7’,‘-v7.3’

之后改为:

save('data.mat', 'name', 'age', '-v7.3')

就可以了。

参考链接:https://blog.csdn.net/lee18254290736/article/details/103417095

posted @ 2021-01-21 01:09  何弈  阅读(2613)  评论(0编辑  收藏  举报
你好