[Numpy-discussion] how to combine (stack) two masked arrays?

Jim Vickroy Jim.Vickroy@noaa....
Thu Mar 1 16:53:34 CST 2007

Thanks for the quick response!
Please see my in-line comments below.

Pierre GM wrote:
> Hello,
> The simplest is:
> rescaled[rescaled.mask]=clipped_mask[rescaled.mask]
> 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 
above code)!

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.
> <pushing_product> 
> 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
> </pushing_product>
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
> P.
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070301/ce51ced5/attachment.html 

More information about the Numpy-discussion mailing list