我使用以下代码将 Matlab 加载到 Python 中
import h5py
import numpy as np
filepath = 'file.mat'
arrays = {}
f = h5py.File(filepath)
for k, v in f.items():
arrays[k] = np.array(v)
a=arrays['data']
a.shape
问题是在Matlab中
>> size(dataset)
ans =
64 50 21 2
在Python中
>>> a.shape
(2, 21, 50, 64)
知道为什么以及如何解决这个问题吗?
numpy.moveaxis()
可以做到这一点:
import numpy as np
tmp = np.zeros((2, 21, 50, 64))
tmp2 = np.moveaxis(tmp, [0, 1, 2, 3], [3, 2, 1, 0])
tmp2.shape
Out[5]: (64, 50, 21, 2)