【问题标题】:open .mat file with python 2.7使用 python 2.7 打开 .mat 文件
【发布时间】:2018-12-18 05:08:52
【问题描述】:

我正在寻找与此 python 3.6 代码等效的代码:

import scipy.io as sio
file = sio.loadmat('file.mat')
data = file['data']

我必须在 python 2.7 中做同样的事情,我试过了

import h5py
f = h5py.File('file.mat')

但它不起作用,你有什么想法吗?

谢谢

【问题讨论】:

  • 为什么不使用 SciPy 方法? SciPy 支持 Python 2.7。

标签: python python-2.7 mat-file


【解决方案1】:

如果不想使用 scipy,可以使用 h5py。它支持保存为 v3.7 数组的 Matlab 数组。

import numpy as np
import h5py 

f = h5py.File('file.mat','r') 
data = f.get('data/variable_name') 

# convert to numpy array
data = np.array(data)

save('filename', '-v7.3', 'var1'); 那样保存来自 Matlab 的数据

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 1970-01-01
    • 2019-09-25
    相关资源
    最近更新 更多