logo       

Re: Reshaing continued: msg#00018

python.numeric.general

Subject: Re: Reshaing continued

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@xxxxxxxx>
Dept. of Physics & Astronomy, Cal State Northridge

Attachment: signature.asc
Description: This is a digitally signed message part

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise