[Numpy-discussion] putmask/take ?

Stefan van der Walt stefan at sun.ac.za
Fri Sep 22 02:13:02 CDT 2006


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.
> 
> >>> import numpy
> >>> x = N.arange(12.)
> >>> m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]
> >>> i = N.nonzero (m)[0]
> >>> w = N.array([-1, -2, -3, -4.])
> >>> x.putmask(w,m)

You can also use N.place:

    Similar to putmask arr[mask] = 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éfan




More information about the Numpy-discussion mailing list