# [Numpy-discussion] Reshaing continued

Stephen Walton stephen.walton at csun.edu
Sun Sep 5 17:30:10 EDT 2004

```On Sun, 2004-09-05 at 02:44, Karthikesh Raju wrote:

> example a = reshape(arange(0,18),(2,3,3))
>
> a[0,:,:], a[1,:,:] should be rows wise extracts like
>
> a[0,:,:] = 0 3 6
>            1 4 7
>            2 5 8
>

I'm not certain why you expect the transpose of the actual result here.
There are two possibilities. MATLAB arrays are column major (first index
varies most rapidly), so in MATLAB (one-based indexing):

>> A=reshape([0:17],[2,3,3]);
>> M=reshape(A(1,:,:),[3,3])
M =

0     6    12
2     8    14
4    10    16

This is the same thing you would get in MATLAB from
M=reshape([0,2,4,6,8,10,12,14,16],[3,3])

numarray arrays are row major (last index varies most rapidly), so in
numarray:

>>> A=reshape(arange(0,18), (2,3,3))
>>> M=A[0,:,:]
>>> M
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])

This is the same thing you get for M=reshape(arange(0,9),(3,3)).

--
Stephen Walton <stephen.walton at csun.edu>
Dept. of Physics & Astronomy, Cal State Northridge
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20040905/ffb0e9ca/attachment.sig>
```