Matthew Brett schrieb:
> Hi,
>>>>> Therefore I am convinced that a 1d vector
>>> in numpy (a row vector) corresponds more naturally to a column vector in
>>> matlab. I see the argument that [1:12] in matlab is a row vector, but I
>>> think this is simply to be consistent with the direct entry of matrices
>>> ([1:12; 1:12] is a 2x12 matrix) and to be more economic in displaying on
>>> screen. In my opinion this is not sufficient to deduce what should be
>>> the default shape of a 1d vector in matlab.
>>>>> Also, I believe matlab is inconsistent on this point anyway -- isn't
>> A(:) (basically ".ravel()") a column vector?
>>>> I agree it's not completely clear what matlab thinks.
>> However, at the moment we have:
>> In [19]: arr = np.arange(5)
>> In [20]: arr.shape
> Out[20]: (5,)
>> In [21]: np.atleast_2d(arr).shape
> Out[21]: (1, 5)
>> In [22]: scipy.io.savemat('afile.mat', {'arr':arr})
>> In [24]: vars = scipy.io.loadmat('afile.mat')
>> In [25]: vars['arr'].shape
> Out[25]: (5, 1)
>> I think that is moderately surprising.
>
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.
Gregor