Re: [Numpy-discussion] Inplace index suprise

2008-03-20 Thread Gael Varoquaux
On Thu, Mar 20, 2008 at 06:43:21PM -0300, Lisandro Dalcin wrote: > I think you are wrong, here THERE ARE tmp arrays involved... numpy has > to copy data if indices are not contiguous or strides (in the sense of > actually using a slice) > In [1]: from numpy import * > In [2]: A = array([0,0,0]) >

Re: [Numpy-discussion] Inplace index suprise

2008-03-20 Thread Lisandro Dalcin
I think you are wrong, here THERE ARE tmp arrays involved... numpy has to copy data if indices are not contiguous or strides (in the sense of actually using a slice) In [1]: from numpy import * In [2]: A = array([0,0,0]) In [3]: B = A[[0,1,2]] In [4]: print B.base None In [5]: C = A[0:3] In [6]: p

Re: [Numpy-discussion] Inplace index suprise

2008-03-20 Thread James Philbin
Hi, > More importantly, it is technically impossible because of the way that > *Python* works. See the thread "Histograms via indirect index arrays" > for a detailed explanation. > > http://projects.scipy.org/pipermail/numpy-discussion/2006-March/006877.html OK, that makes things much clearer

Re: [Numpy-discussion] Inplace index suprise

2008-03-20 Thread Anne Archibald
On 20/03/2008, Gael Varoquaux <[EMAIL PROTECTED]> wrote: > On Thu, Mar 20, 2008 at 06:17:44PM +, James Philbin wrote: > > Hi, > > > > This cannot work, because the inplace operation does not > > > take place as a for loop. > > Well, this would be fine if I was assigning the values to temp

Re: [Numpy-discussion] Inplace index suprise

2008-03-20 Thread Robert Kern
On Thu, Mar 20, 2008 at 1:35 PM, Gael Varoquaux <[EMAIL PROTECTED]> wrote: > On Thu, Mar 20, 2008 at 06:17:44PM +, James Philbin wrote: > > Hi, > > > > This cannot work, because the inplace operation does not > > > take place as a for loop. > > Well, this would be fine if I was assigning

Re: [Numpy-discussion] Inplace index suprise

2008-03-20 Thread Gael Varoquaux
On Thu, Mar 20, 2008 at 06:17:44PM +, James Philbin wrote: > Hi, > > This cannot work, because the inplace operation does not > > take place as a for loop. > Well, this would be fine if I was assigning the values to tempories as > you suggest. However, the operation should be performed inpla

Re: [Numpy-discussion] Inplace index suprise

2008-03-20 Thread James Philbin
Hi, > This cannot work, because the inplace operation does not > take place as a for loop. Well, this would be fine if I was assigning the values to tempories as you suggest. However, the operation should be performed inplace and this is what I don't understand - why is there no for loop? I thin

Re: [Numpy-discussion] Inplace index suprise

2008-03-20 Thread Gael Varoquaux
On Thu, Mar 20, 2008 at 05:42:05PM +, James Philbin wrote: > I was suprised to see this result: > >>> import numpy as N > >>> A = N.array([0,0,0]) > >>> A[[0,1,1,2]]+=1 > >>> A > array([1, 1, 1]) > Is this expected? Working on the principle of least surprise I would > expect [1,2,1] to be outp

[Numpy-discussion] Inplace index suprise

2008-03-20 Thread James Philbin
Hi, I was suprised to see this result: >>> import numpy as N >>> A = N.array([0,0,0]) >>> A[[0,1,1,2]]+=1 >>> A array([1, 1, 1]) Is this expected? Working on the principle of least surprise I would expect [1,2,1] to be output. Thanks, James ___ Numpy-d

[Numpy-discussion] Inplace index suprise

2008-03-20 Thread James Philbin
Hi, I was suprised to see this result: >>> import numpy as N >>> A = N.array([0,0,0]) >>> A[[0,1,1,2]]+=1 >>> A array([1, 1, 1]) Is this expected? Working on the principle of least surprise I would expect [1,2,1] to be output. Thanks, James ___ Numpy-d