python - 使用 hdf5storage 从 Python 创建 .mat v7.3 文件

标签 python hdf5 mat

有什么方法可以从 Python 创建 .mat v7.3 文件吗?我已经成功地从 Python 创建 hdf5 文件,但无法将它们转换为 .mat v7.3 文件。 我找到了一个名为 hdf5storage 的包但我不知道如何使用它。

最佳答案

示例(需要 Python >= 2.6 以及 NumPy 和 h5py >= 2.1 软件包):

import hdf5storage # get code on https://pypi.python.org/pypi/hdf5storage/0.1.3

matcontent = {}
matcontent[u'some_numbers'] = [10, 50, 20] # each key must be a unicode string
hdf5storage.write(matcontent, '.', 'test.mat', store_python_metadata=False, matlab_compatible=True)

在 Matlab 中:

enter image description here


如果你想在 Matlab 中使用矩阵而不是元胞数组:

import hdf5storage # get code on https://pypi.python.org/pypi/hdf5storage/0.1.3
import numpy as np

matcontent = {}
matcontent[u'some_numbers'] = np.array([10, 50, 20]) # each key must be a unicode string
hdf5storage.write(matcontent, '.', 'test2.mat', matlab_compatible=True)

enter image description here

您会注意到,第二个示例要快得多 (>x10)。


更一般而言,请参阅 data storage matching 的文档:

enter image description here

关于python - 使用 hdf5storage 从 Python 创建 .mat v7.3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23333978/

相关文章:

python - 对两列应用操作返回 'None'

python - 通过 tf-idf 特征选择重用 sklearn 文本分类模型

python - 如何摆脱 NaturalNameWarning?

c++ - OpenCV:改变像素的颜色

opencv - openCV中的总和

c++ - 如何清除openCV中的窗口内容

python - 是否可以删除(不仅仅是取消链接)类(class)?

python - 在 Python 中将 nx.write_gexf 用于在节点和边上具有字典数据的图形

python - 为什么如果我将多个空的 Pandas 系列放入 hdf5 hdf5 的大小如此巨大?

python-3.x - Pandas - 使用 to_hdf 添加同名数据框使文件大小翻倍