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

Matthew Brett matthew.brett@gmail....
Fri Jan 23 01:39:16 CST 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