Re: [Numpy-discussion] Can not update a submatrix

2008-02-01 Thread Francesc Altet
A Thursday 31 January 2008, Francesc Altet escrigué: > A Wednesday 30 January 2008, Timothy Hochberg escrigué: > > [...a fine explanation by Anne and Timothy...] > > Ok. As it seems that this subject has interest enough, I went ahead > and created a small document about views vs copies at: > > http

Re: [Numpy-discussion] Can not update a submatrix

2008-01-31 Thread Francesc Altet
A Wednesday 30 January 2008, Timothy Hochberg escrigué: > [...a fine explanation by Anne and Timothy...] Ok. As it seems that this subject has interest enough, I went ahead and created a small document about views vs copies at: http://www.scipy.org/Cookbook/ViewsVsCopies I think it resumes what

Re: [Numpy-discussion] Can not update a submatrix

2008-01-31 Thread Nadav Horesh
Thanks for your explanation. It explains also the following: >>> R = N.arange(9).reshape(3,3) >>> ax = [0,2] >>> U = R[ax,:] >>> U array([[0, 1, 2], [6, 7, 8]]) >>> U[:] = 100 >>> U array([[100, 100, 100], [100, 100, 100]]) >>> R# No change since U is a copy array([[0, 1, 2],

Re: [Numpy-discussion] Can not update a submatrix

2008-01-30 Thread Timothy Hochberg
On Jan 30, 2008 12:43 PM, Anne Archibald <[EMAIL PROTECTED]> wrote: > On 30/01/2008, Francesc Altet <[EMAIL PROTECTED]> wrote: > > A Wednesday 30 January 2008, Nadav Horesh escrigué: > > > In the following piece of code: > > > >>> import numpy as N > > > >>> R = N.arange(9).reshape(3,3) > > > >>>

Re: [Numpy-discussion] Can not update a submatrix

2008-01-30 Thread Anne Archibald
On 30/01/2008, Francesc Altet <[EMAIL PROTECTED]> wrote: > A Wednesday 30 January 2008, Nadav Horesh escrigué: > > In the following piece of code: > > >>> import numpy as N > > >>> R = N.arange(9).reshape(3,3) > > >>> ax = [1,2] > > >>> R > > > > array([[0, 1, 2], > >[3, 4, 5], > >[

Re: [Numpy-discussion] Can not update a submatrix

2008-01-30 Thread Nadav Horesh
Numerical Python Subject: Re: [Numpy-discussion] Can not update a submatrix or you can maybe use numpy.ix_: ax = [1,2] R[numpy.ix_(ax,ax)] = 100 hth, L. On 1/30/08, lorenzo bolla <[EMAIL PROTECTED]> wrote: > > you simply need to change the definition of ax: > ax = slice(1,3) &g

Re: [Numpy-discussion] Can not update a submatrix

2008-01-30 Thread lorenzo bolla
or you can maybe use numpy.ix_: ax = [1,2] R[numpy.ix_(ax,ax)] = 100 hth, L. On 1/30/08, lorenzo bolla <[EMAIL PROTECTED]> wrote: > > you simply need to change the definition of ax: > ax = slice(1,3) > > and all works fine. > L. > > On 1/30/08, Francesc Altet <[EMAIL PROTECTED]> wrote: > > > >

Re: [Numpy-discussion] Can not update a submatrix

2008-01-30 Thread Charles R Harris
On Jan 30, 2008 8:21 AM, Nadav Horesh <[EMAIL PROTECTED]> wrote: > But: > > > >>> R[ax,:] = 100 > >>> R > array([[ 0, 1, 2], >[100, 100, 100], >[100, 100, 100]]) > >>> R[:,ax] = 200 > >>> R > array([[ 0, 200, 200], >[100, 200, 200], >[100, 200, 200]]) > > Do

Re: [Numpy-discussion] Can not update a submatrix

2008-01-30 Thread lorenzo bolla
you simply need to change the definition of ax: ax = slice(1,3) and all works fine. L. On 1/30/08, Francesc Altet <[EMAIL PROTECTED]> wrote: > > A Wednesday 30 January 2008, Nadav Horesh escrigué: > > In the following piece of code: > > >>> import numpy as N > > >>> R = N.arange(9).reshape(3,3) >

Re: [Numpy-discussion] Can not update a submatrix

2008-01-30 Thread Hans Meine
Am Mittwoch, 30. Januar 2008 16:21:40 schrieb Nadav Horesh: > But: > >>> R[ax,:] = 100 This is calling __setitem__, i.e. does not create either a view or a copy. Non-contiguous views (e.g. using [::2]) are also possible AFAIK, but fancy indexing is something different. -- Ciao, / / /--/

Re: [Numpy-discussion] Can not update a submatrix

2008-01-30 Thread Nadav Horesh
But: >>> R[ax,:] = 100 >>> R array([[ 0, 1, 2], [100, 100, 100], [100, 100, 100]]) >>> R[:,ax] = 200 >>> R array([[ 0, 200, 200], [100, 200, 200], [100, 200, 200]]) Do I get an array view only if the array is contiguous? Nadav. On Wed, 2008-01-30 at 16:08 +0

Re: [Numpy-discussion] Can not update a submatrix

2008-01-30 Thread Francesc Altet
A Wednesday 30 January 2008, Nadav Horesh escrigué: > In the following piece of code: > >>> import numpy as N > >>> R = N.arange(9).reshape(3,3) > >>> ax = [1,2] > >>> R > > array([[0, 1, 2], >[3, 4, 5], >[6, 7, 8]]) > > >>> R[ax,:][:,ax] = 100 > >>> R > > array([[0, 1, 2], >

[Numpy-discussion] Can not update a submatrix

2008-01-30 Thread Nadav Horesh
In the following piece of code: >>> import numpy as N >>> R = N.arange(9).reshape(3,3) >>> ax = [1,2] >>> R array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) >>> R[ax,:][:,ax] = 100 >>> R array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) Why R is not updated? I was expecting: >>> R ar