[SciPy-User] Numpy/MATLAB difference in array indexing

federico vaggi vaggi.federico at gmail.com
Sun Mar 18 18:18:26 EDT 2012


Hi everyone,

I was trying to port some code from MATLAB to Scipy, and I noticed a slight
bug in the functionality of numpy.tile vs repmat in matlab:

For example:

a = np.random.rand(10,2)

b = tile(a[:,1],(1,5))

b.shape
Out[86]: (1, 50)

While MATLAB gives:

>>  a = rand(10,2);
>> b = repmat(a(:,1),[1,5]);
>> size(b)

ans =

    10     5

This is obviously trivial to fix**, but I'm wondering what causes the
difference?  If you take a vertical slice of an array in numpy that's seen
as a row vector, while in MATLAB its seen as a column vector?

Is it worth making a note in here:
http://www.scipy.org/NumPy_for_Matlab_Users ?

Federico

**
The easiest way I found was:

b = tile(a[:,1],(5,1)).T
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20120318/809281af/attachment.html>


More information about the SciPy-User mailing list