python - 如何在Python中打开以下mat文件

标签 python hdf5

我在 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/

相关文章:

python - 使用正则表达式搜索和过滤 pandas 数据框

python - 使用 h5py 编写大型 hdf5 数据集

python - 在具有 500e6 行的 hdf5 pytable 中查找重复项

c++ - 由于使用 CMake 的 HDF5 兼容性问题导致链接错误

python - 如何在没有 for 循环的情况下比较 pandas 中的两个数据帧?

python (pyodbc):Run ms access query from python results to size error

python - 使用脚本参数在 Snakemake 中指定 Python 版本

python - getBatch 从 MQTTTextStreamSource 返回的 DataFrame 没有 isStreaming=true

python - 写入多个 HDF5 文件时 Windows 中打开的文件过多

python - 保存到 hdf5 非常慢(Python 卡住)