matまたはnpyファイルを読み取り、matファイルをnpyファイルとして保存する(またはnpyをmatとして保存する)ためのPythonメソッド



Python Method Reading Mat



numpy h5py scipy


  • 方法1(MATLABをダブルクリックして開くとエラーが発生しました:MATファイル*********。matを読み取れません。バイナリMATファイルではありません。-ASCIIをロードしてテキストとして読み取ってみてください。):
import numpy as np matrix = np.load('yourfile.npy') f = h5py.File('yourfile.mat', 'w') f.create_dataset('dataname', data=matrix) # here will not transpose data
  • 方法2(scipyを使用):
from scipy import io mat = np.load('rlt_gene_features.npy-layer-3-train.npy') io.savemat('gene_features.mat', {'gene_features': mat})