[SciPy-dev] Matlab io bug; request for advice
Fri Feb 20 06:48:07 CST 2009
Nathan Bell schrieb:
> On Thu, Feb 19, 2009 at 1:45 PM, Gregor Thalhammer
> <email@example.com> wrote:
>> Why not converting matlab 1xN or Nx1 arrays to numpy 1d arrays when
>> loading from a matlab file? (If I remember correctly, this has been the
>> case long time ago, at least in some of the predecessors of scipy.io). I
>> guess this change would create more protest, at least on this list,
>> since it would break python code instead of matlab code.
> If I store a 1xN or Nx1 array in a .mat I expect the matrix I read
> back later to have the same dimensions. Think of how obnoxious it
> would be if I had a code that (depending on the input) might write a
> Nx3 or a Nx2 or a Nx1 matrix to disk, and then read that back at a
> later time.
> If someone has a proper 2d matrix in numpy we ought to respect their
> (explicit) intentions.
You can use exactly the same argument to propose the old behaviour: If I
store a 1d array in a .mat I expect the vector I read back later to have
the same dimensions. Now we can argue what is the more common use case,
1d arrays or 1xN arrays? Which of them should behave consistently?
Generally, I think it's a very bad choice to use a matlab file to store
and retrieve numpy arrays, since you loose information about the shape
of the arrays, in one or the other way. The matlab read/write functions
in scipy.io are useful to exchange data between numpy and matlab. If I
save a vector in matlab, isn't it natural to get a 1d array when load it
More information about the Scipy-dev