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

Wes McKinney wesmckinn@gmail....
Sun Mar 18 19:23:34 CDT 2012


On Sun, Mar 18, 2012 at 6:37 PM, Pauli Virtanen <pav@iki.fi> wrote:
> 18.03.2012 23:18, federico vaggi kirjoitti:
>> 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))
>
> a[:,1] is an 1-d array, and therefore considered as a (1, N) vector in
> 2-d context. This is not a bug --- the Numpy constructs do not always
> map exactly to Matlab ones.
>
> --
> Pauli Virtanen
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

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

In [4]: b.shape
Out[4]: (10, 5)


More information about the SciPy-User mailing list