[Numpy-discussion] how to combine (stack) two masked arrays?
Thu Mar 1 16:53:34 CST 2007
Thanks for the quick response!
Please see my in-line comments below.
Pierre GM wrote:
> The simplest is:
> But for this particular kind of operation, I don't think that you need masked
> array at all: this could do the trick
>>>> rescaled = clipped.copy()
>>>> inside = numpy.logical_and(clipped>=123, clipped<=354)
>>>> outside = numpy.logical_not(inside)
>>>> newrescaled[inside] = 5*clipped[inside]
>>>> newrescaled[outside] = clipped[outside]
Great; that is slick (replaced *newrescaled* with *rescaled* in the
I approached numpy with a preconceived notion of how to perform this
task (i.e., masked arrays) and did not look at the broader set of
package capabilities <frown>
> A side note: when using numpy.core.ma, it's more efficient to deal w/ the
> _data and _mask parts separately than at once.
Thanks for the tip.
> You may want to try an alternative implementation of maskedarray, available in
> the sandbox of the scipy SVN. I'd be very happy to have your feedback
While browsing the archived discussions, I did see mention of this, but
decided to avoid it because I was a newbie.
> Let me know if this helps
> Numpy-discussion mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion