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

Robert Kern robert.kern at gmail.com
Fri Jan 23 02:42:40 EST 2009


On Fri, Jan 23, 2009 at 01:39, Matthew Brett <matthew.brett at gmail.com> 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(4, numpy.bool)
> a[b] += 1

Judging from his for loop, he does want the integer array. He's doing
something like histogramming.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list