[SciPy-dev] Matlab io bug; request for advice

Matthew Brett matthew.brett@gmail....
Thu Feb 19 11:30:36 CST 2009


>> 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.



More information about the Scipy-dev mailing list