相关疑难解决方法(0)

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

我有一个由matlab创建的struct数组,并存储在v7.3格式的mat文件中:

struArray = struct('name', {'one', 'two', 'three'}, 
                   'id', {1,2,3}, 
                   'data', {[1:10], [3:9], [0]})
save('test.mat', 'struArray', '-v7.3')
Run Code Online (Sandbox Code Playgroud)

现在我想通过python使用h5py读取这个文件:

data = h5py.File('test.mat')
struArray = data['/struArray']
Run Code Online (Sandbox Code Playgroud)

我不知道如何逐个获取结构数据struArray:

for index in range(<the size of struArray>):
    elem = <the index th struct in struArray>
    name = <the name of elem>
    id = <the id of elem>
    data = <the data of elem>
Run Code Online (Sandbox Code Playgroud)

python matlab hdf5 h5py mat

15
推荐指数
1
解决办法
1万
查看次数

使用python h5py读取.mat文件中的所有变量

我试图从'.mat'v7.3文件中提取所有变量,并将它们转换为NumPy数组.有没有办法一般地执行此操作,最好不需要指定变量名称?如何从h5py.File获取所有当前变量名称,然后检查它们的尺寸?

防爆.

 import numpy as np, h5py

 file = h5py.File('data.mat','r')
 for "all variables in mat file"
     ...fill numpy array
 end
Run Code Online (Sandbox Code Playgroud)

python matlab numpy h5py

2
推荐指数
1
解决办法
8250
查看次数

标签 统计

h5py ×2

matlab ×2

python ×2

hdf5 ×1

mat ×1

numpy ×1