[Numpy-discussion] Appending/combining masked arrays
Gökhan Sever
gokhansever at gmail.com
Wed Sep 29 18:01:49 EDT 2010
> 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.
Here it comes -> http://projects.scipy.org/numpy/ticket/1623
> 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.
Does this look good?
I[256]: a = np.ma.masked_equal([1,2,3], value=2)
I[257]: b = np.ma.masked_equal([4,3,2, 5], value=2)
I[258]: c = np.append(a.data, b.data)
I[251]: cmask = np.append(np.ma.getmaskarray (a), np.ma.getmaskarray (b))
I[252]: c
O[252]: array([1, 2, 3, 4, 3, 2, 5])
I[253]: cmask
O[253]: array([False, True, False, False, False, True, False], dtype=bool)
I[254]: d = np.ma.masked_array(c, cmask)
I[255]: d
O[255]:
masked_array(data = [1 -- 3 4 3 -- 5],
mask = [False True False False False True False],
fill_value = 999999)
Probably I will need a loop to construct a similar ma array for 7
different masked arrays in a list.
--
Gökhan
More information about the NumPy-Discussion
mailing list