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
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
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],
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)
> > > >>>
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],
> >[
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
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:
> >
> >
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
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)
>
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, / /
/--/
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
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],
>
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
13 matches
Mail list logo