% save .mat file in the matlab
train_set_x=1:50*1*51*61*23;
train_set_x=reshape(train_set_x,[50,1,51,61,23]);
save(['pythonTest.mat'],'train_set_x','-v7.3');
데이터는 (50,1,51,61,23)의 크기입니다.파이썬에서 .mat 파일을 읽습니다. 그러나 데이터의 모양이 변경되었습니다
이 link 명령으로 Python에서 .mat 파일을로드합니다. train_set_x.shape의
import numpy as np, h5py
f = h5py.File('pythonTest.mat', 'r')
train_set_x = f.get('train_set_x')
train_set_x = np.array(train_set_x)
출력은 (23L, 61L, 51L, 1L, 50L)
이며 다음과 같이
코드이다. (50L, 1L, 51L, 61L, 23L)
이 될 것으로 예상됩니다. 그래서
train_set_x=np.transpose(train_set_x, (4,3,2,1,0))
내가 파이썬과 MATLAB 사이의 데이터 형태의 변화에 대한 호기심으로 모양을 변경했습니다. 내 코드에 오류가 있습니까?
관련 : http://stackoverflow.com/q/24116713/1714410 – Shai
이전의'.mat' 버전의 경우,'scipy.io.loadmat'는 MATLAB과 같은 모양이지만'order = 'F '' 배열을 만듭니다. 따라서 그것은 이러한 차이를 숨 깁니다. – hpaulj
@ hpaulj : 일찌감치는 무엇을 의미합니까? "늦은"매트 버전의 동작 변경 사항은 무엇입니까? – Eric