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

Matthew Brett matthew.brett at gmail.com
Fri Jan 23 02:39:16 EST 2009


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



More information about the NumPy-Discussion mailing list