# 读取.mat文件所用到的包:scipy.io 或 h5py
import h5py
matr = h5py.File('file_name.mat','w')
#使用keys()方法查看字典有几个主键
print(matr.keys())
#或者:
#通过scipy.io读取.mat文件:
import scipy.io as io
matr = io.loadmat('file_name.mat')
______
#假设字典中'data'是你要的数据:
data = matr['data']
#转换为.npy文件:
import numpy as np
numpy_data = np.transpose(data)
#保存为numpy数组文件(.npy文件)
np.save('numpy_data.npy',numpy_data)
__________________________________________________________
# .npy 文件转换为.mat文件:
#加载.npy文件:
numpy_file = np.load('file_name.npy')
#通过scipy.io转换:
import scipy.io as io
io.savemat('file_name.mat',{'data':numpy_file})
# 通过h5py转换:
import h5py
file = h5py.File('your_file_name.mat','w')
file.creat_dataset('data',data=numpy_file)