Python-created HDF5 dataset transposed in Matlab

前端 未结 3 464
情歌与酒
情歌与酒 2020-12-20 16:04

I have some data that I share between Python and Matlab. I used to do it by saving NumPy arrays in MATLAB-style .mat files but would like to switch to HDF5 datasets. However

3条回答
  •  一个人的身影
    2020-12-20 16:28

    When reading data from MatLab, dimensions of the data read need to be permuted to retrieve data layout. To do so, permute function is used. The code below gives the general case with any number of dimensions

    rawdata = h5read(h5Filename,h5Dataset);
    ndim = numel(size(rawdata));
    data = permute(rawdata,[ndim:-1:1]);
    

    When one works with 2D data, one can only transpose result from h5read

    data = h5read(h5Filename,h5Dataset)';
    

提交回复
热议问题