Reputation: 2372
I downloaded a dataset which contains a MATLAB file called 'depths.mat' which contains a 3-dimensional matrix with the dimensions 480 x 640 x 1449. These are actually 1449 images, each with the dimension 640 x 480. I successfully loaded it into python using the scipy library but the problem is the unusual order of the dimensions. This makes Python think that there are 480 images with the dimensions 640 x 1449. I tried to reshape the matrix in python, but a simple reshape operation did not solve my problem.
Any suggestions are welcome. Thank you.
Upvotes: 0
Views: 69
Reputation: 35525
You misunderstood. You do not want to reshape, you want to transpose it. In MATLAB, arrays are A(x,y,z)
while in python they are P[z,y,x]
. Make sure that once you load the entire matrix, you change the first and last dimensions.
You can do this with the swapaxes
function, but beware! it does not make a copy nor change the the data, just changes how the higher level indices of nparray
access the internal memory. Your best chances if you have enough RAM is to make a copy and dump the original.
Upvotes: 2