[Numpy-discussion] Appending/combining masked arrays

Pierre GM pgmdevlist@gmail....
Wed Sep 29 16:37:39 CDT 2010

On Sep 29, 2010, at 11:01 PM, Gökhan Sever wrote:

> Hello,
> Consider these two simple masked arrays:
> I[188]: a = np.ma.masked_equal([1,2,3], value=2)
> I[189]: b = np.ma.masked_equal([4,3,2], value=2)
> An operation like this voids the mask:
> I[190]: np.append(a,b)
> O[190]:
> masked_array(data = [1 2 3 4 3 2],
>             mask = False,
>       fill_value = 999999)

You're using a standard numpy function on a masked array. It's hardly surprising that you run into some issues. You should use the np.ma equivalent. Except of course that the equivalent doesn't exist yet... Please open a ticket.

In the mean time, do it manually:
* combining the .data of each item (masked array) of your list is straightforward
* repeat for the masks. I advise you to use the getmaskarray function to get the mask of each item, otherwise you may get a `nomask` in the middle which will complicate things
* combine the the two results in a new masked array.

More information about the NumPy-Discussion mailing list