Re: [Numpy-discussion] Numpy unexpected (for me) behaviour

2009-01-23 Thread Robert Kern
On Fri, Jan 23, 2009 at 02:10, V. Armando Sole wrote: > At 01:44 23/01/2009 -0600, Robert Kern wrote: >>It is an inevitable consequence of several features interacting >>together. Basically, Python expands "a[b] += 1" into this: >> >> c = a[b] >> d = c.__iadd__(1) >> a[b] = d >> >>Basically,

Re: [Numpy-discussion] Numpy unexpected (for me) behaviour

2009-01-23 Thread V. Armando Sole
At 01:44 23/01/2009 -0600, Robert Kern wrote: >It is an inevitable consequence of several features interacting >together. Basically, Python expands "a[b] += 1" into this: > > c = a[b] > d = c.__iadd__(1) > a[b] = d > >Basically, the array c doesn't know that it was created by indexing a, >so

Re: [Numpy-discussion] Numpy unexpected (for me) behaviour

2009-01-22 Thread Matthew Brett
> Judging from his for loop, he does want the integer array. He's doing > something like histogramming. Yup, thanks, just goes to show that it's not good to send emails after a glass of wine late at night with slight jetlag. Matthew ___ Numpy-discussion

Re: [Numpy-discussion] Numpy unexpected (for me) behaviour

2009-01-22 Thread Robert Kern
On Fri, Jan 23, 2009 at 01:11, V. Armando Sole wrote: > Hello, > > In an effort to suppress for loops, I have arrived to the following situation. > > Through vectorial logical operations I generate a set of indices for which > the contents of an array have to be incremented. My problem can be redu

Re: [Numpy-discussion] Numpy unexpected (for me) behaviour

2009-01-22 Thread Robert Kern
On Fri, Jan 23, 2009 at 01:39, Matthew Brett wrote: > Hi, > >> #This does not work >> import numpy >> a=numpy.zeros(10) >> b=numpy.ones(4, numpy.int) >> a[b] += 1 > > The problem here is that you are setting a[1] to a[1]+1. > > I think you want: > > import numpy > a=numpy.zeros(10) > b=numpy.ones

Re: [Numpy-discussion] Numpy unexpected (for me) behaviour

2009-01-22 Thread Matthew Brett
Hi, > #This does not work > import numpy > a=numpy.zeros(10) > b=numpy.ones(4, numpy.int) > a[b] += 1 The problem here is that you are setting a[1] to a[1]+1. I think you want: import numpy a=numpy.zeros(10) b=numpy.ones(4, numpy.bool) a[b] += 1 Best, Matthew

[Numpy-discussion] Numpy unexpected (for me) behaviour

2009-01-22 Thread V. Armando Sole
Hello, In an effort to suppress for loops, I have arrived to the following situation. Through vectorial logical operations I generate a set of indices for which the contents of an array have to be incremented. My problem can be reduced to the following: #This works import numpy a=numpy.zeros(1