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

Gregor Thalhammer gregor.thalhammer@gmail....
Thu Feb 19 05:18:01 CST 2009

Matthew Brett schrieb:

> However, matlab tends to think of an unshaped vector as being a row vector:
>>> a = 1:12;
>>> size(a)
> ans =
>      1    12
> And numpy thinks the same:
>>>> print np.atleast_2d(np.array([1,2])).shape
> (1, 2)
> It seems to me then, that I should assume the same, that a 1
> dimensional array is a row vector.   However, this will change the
> matlab shape of a 1 d array passed into the matlab mat file routines
> from a column vector to a row vector.
> Do y'all think I should:
> a) Given this is undocumented anyway, just switch to the row vector
> b) Keep 1d arrays as column vectors
> c) Raise a warning and change for a future release
I vote for option b: keep 1d arrays as column vectors. Numpy and matlab 
follow two fundamentally different conventions: numpy uses by default C 
contiguous arrays, matlab Fortran contiguous arrays. If A is a matrix, 
in numpy 'for vector in A: ...' loops over the row vectors, in matlab 
'for vector = A' loops over the colum vectors. Matlab follows more 
closely the notation mathematicians prefer, e.g., indices start with 0, 
1d vectors are column vectors. 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.


More information about the Scipy-dev mailing list