栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何通过h5py读取v7.3 mat文件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何通过h5py读取v7.3 mat文件?

Matlab
7.3文件格式使用h5py并非十分容易。它依赖于HDF5参考,参见。h5py参考文献文档。

>>> import h5py>>> f = h5py.File('test.mat')>>> list(f.keys())['#refs#', 'struArray']>>> struArray = f['struArray']>>> struArray['name'][0, 0]  # this is the HDF5 reference<HDF5 object reference>>>> f[struArray['name'][0, 0]].value  # this is the actual dataarray([[111],       [110],       [101]], dtype=uint16)

阅读

struArray(i).id

>>> f[struArray['id'][0, 0]][0, 0]1.0>>> f[struArray['id'][1, 0]][0, 0]2.0>>> f[struArray['id'][2, 0]][0, 0]3.0

请注意,Matlab将数字存储为大小为(1,1)的数组,因此最终存储

[0, 0]
了该数字。

阅读

struArray(i).data

>>> f[struArray['data'][0, 0]].valuearray([[  1.],       [  2.],       [  3.],       [  4.],       [  5.],       [  6.],       [  7.],       [  8.],       [  9.],       [ 10.]])

要读取

struArray(i).name
,必须将整数数组转换为字符串:

>>> f[struArray['name'][0, 0]].value.tobytes()[::2].depre()'one'>>> f[struArray['name'][1, 0]].value.tobytes()[::2].depre()'two'>>> f[struArray['name'][2, 0]].value.tobytes()[::2].depre()'three'


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/650591.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号