From: Stefan v. d. W. <st...@su...> - 2006-09-22 07:13:39
|
On Thu, Sep 21, 2006 at 08:35:02PM -0400, P GM wrote: > Folks, > 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) You can also use N.place: Similar to putmask arr[mask] =3D vals but the 1D array vals has the same number of elements as the non-zero values of mask. Inverse of extract. > >>> x.take(i) > >>> N.allclose(x.take(i),w) > False Regards St=E9fan |