我在 MATLAB 中使用“-v7.3”标志创建了以下 .mat 文件。由于数据量巨大,我需要这个标志。我在 MATLAB 中使用以下命令来保存该文件。
save('sample10_properties.mat', 'stats','-v7.3')
这里是数据链接
https://drive.google.com/file/d/195fj6Tl1n_drS8R_A6bdbOEc3rGkiMqS/view?usp=sharing
我可以在 python 中看到 stats 变量,但我不知道如何访问。任何帮助将不胜感激。
import numpy as np
import h5py
f = h5py.File('sample10_properties.mat')
f.keys() [u'#refs#', u'#subsystem#', u'stats']
f.values() [<HDF5 group "/#refs#" (13951 members)>, <HDF5 group "/#subsystem#" (1 members)>, <HDF5 dataset "stats": shape (1, 6), type "<u4">]
stats 变量的大小为 (1390, 18)。 谢谢
最佳答案
如果你想加载单个值
import h5py
f = h5py.File('sample10_properties.mat','r')
myvar = f['myvar'].value
所有值
import numpy as np
import h5py
f = h5py.File('simdata_020_01.mat','r')
variables = f.items()
for var in variables:
name = var[0]
data = var[1]
print "Name ", name # Name
if type(data) is h5py.Dataset:
# If DataSet pull the associated Data
# If not a dataset, you may need to access the element sub-items
value = data.value
print "Value", value # NumPy Array / Value
我时间紧迫,所以我写得很快,对于任何错误或不适合您的数据,我们深表歉意。
关于python - 如何在Python中打开以下mat文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56023747/