From: Stefan v. d. W. <st...@su...> - 2006-09-22 07:03:26
|
Hi P., On Thu, Sep 21, 2006 at 07:40:39PM -0400, PGM wrote: > I'm running into the following problem with putmask on take. >=20 > >>> import numpy > >>> x =3D N.arange(12.) > >>> m =3D [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1] > >>> i =3D N.nonzero(m)[0] > >>> w =3D N.array([-1, -2, -3, -4.]) > >>> x.putmask(w,m) > >>> x.take(i) > >>> N.allclose(x.take(i),w) According to the putmask docstring: a.putmask(values, mask) sets a.flat[n] =3D v[n] for each n where mask.flat[n] is true. v can be scalar. This would mean that 'w' is not of the right length. Would the following do what you want? import numpy as N m =3D N.array([1,0,0,0,0,0,1,0,0,1,0,1],dtype=3Dbool) w =3D N.array([-1,-2,-3,-4]) x[m] =3D w Regards St=E9fan |