title: Transferring matlab 3D-matrices to python 3D-arrays via scipy.io.loadmat is going wrong
body: <p>I'm considering a problem with Matlab matrices and Python numpy arrays. I have a Code for Medical image processing, given a 3D array as input (512x512 images, 80 slices -> size(image) = (512,512,80). 
  The input is originally given by a NifTI-structure.
  When I load the Nii-file in matlab, i get 512x512x80 as size.
  When I load the Nii-file in python, i get 80x512x512 as size (with array.shape)  </p>
  
  <p>With trying out testmatrices, i found out:
  Matlabs syntax for size: (x = rows, y = columns, z = slices in 3rd dimenson)
  python syntax for size: (z = slices in 3rd dim, x = rows, y = columns)</p>
  
  <p>Now I have to test another data, not given as nii-file, but saved in mat-files. 
  With Scipy's loadmat I can load the matrix easily into my python program.
  But: Now the matrix' size is now (512,512,80) in python as well and the following code now takes 512 slices in the 3rd dimension, 512 rows and 80 columns (instead of 80 slices, 512x512 images).
  I hope this is understandable explanation...</p>
  
  <p>A minimal example:</p>
  
  <p>I load a Matrix in Matlab by:</p>
  
  <pre><code>a = 1:12;
  a = reshape(a, [1 3 4])
  
  a(:,:,1) =
  
       1     2     3
  
  
  a(:,:,2) =
  
       4     5     6
  
  
  a(:,:,3) =
  
       7     8     9
  
  
  a(:,:,4) =
  
      10    11    12
  
  size(a)
  
  ans =
  
       1     3     4
  </code></pre>
  
  <p>With </p>
  
  <pre><code>save a.mat a
  </code></pre>
  
  <p>I save a in a mat file. 
  Now I go on to my python code, using import scipy.io as spio I can access the matfile:</p>
  
  <pre><code>mat = spio.loadmat('a.mat')
  a = mat['a']
  print(a)
  
     Output:
  [[[1 4 7 10]
  
    [2 5 8 11]
  
    [3 6 9 12]]]
  
  print(a.shape)
  
     Output:
  (1,3,4)
  </code></pre>
  
  <p>But this is wrong! It has no 4 slices in 3rd dimension, but rather is just a 3x4 matrix.
  I should be:</p>
  
  <pre><code>[[[ 1 2 3]]
  
   [[ 4 5 6]]
  
   [[ 7 8 9]]
  
   [[10 11 12]]]
  
  with shape (4,1,3)
  </code></pre>
  
  <p>So, How can I load Matlab-Matrices in the exact python order, such that my code takes the right slices? 
  Further am I interested in transferring the resulting python array back to matlab matrices again.</p>
  
  <p>Thank you much in advance!</p>