Hi Chao,<br><br>If you don't mind modifying masked values, then if you write to the underlying ndarray it won't touch the mask:<br><br>>>> a = np.ma.masked_less(np.arange(10),5)<br>>>> a.base[3:6] = 1<br>
>>> a<br>masked_array(data = [-- -- -- -- -- 1 6 7 8 9],<br>             mask = [ True  True  True  True  True False False False False False],<br>       fill_value = 999999)<br><br>Regards,<br>Richard Hattersley<br>

<br><br><div class="gmail_quote">On 10 September 2012 17:43, Chao YUE <span dir="ltr"><<a href="mailto:chaoyuejoy@gmail.com" target="_blank">chaoyuejoy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear all numpy users,<br><br>what's the easy way if I just want to change part of the unmasked array elements into another new value? like an example below:<br>in my real case, I would like to change a subgrid of a masked numpy array to another value, but this grid include both masked and unmasked data.<br>

If I do a simple array[index1:index2, index3:index4] = another_value, those data with original True mask will change into False. I am using numpy 1.6.2.<br>Thanks for any ideas.<br><br clear="all">In [91]: a = np.ma.masked_less(np.arange(10),5)<br>

<br>In [92]: or_mask = a.mask.copy()<br>In [93]: a<br>Out[93]: <br>masked_array(data = [-- -- -- -- -- 5 6 7 8 9],<br>             mask = [ True  True  True  True  True False False False False False],<br>       fill_value = 999999)<br>

<br><br>In [94]: a[3:6]=1<br><br>In [95]: a<br>Out[95]: <br>masked_array(data = [-- -- -- 1 1 1 6 7 8 9],<br>             mask = [ True  True  True False False False False False False False],<br>       fill_value = 999999)<br>

<br><br>In [96]: a = np.ma.masked_array(a,mask=or_mask)<br><br>In [97]: a<br>Out[97]: <br>masked_array(data = [-- -- -- -- -- 1 6 7 8 9],<br>             mask = [ True  True  True  True  True False False False False False],<br>

       fill_value = 999999)<span class="HOEnZb"><font color="#888888"><br><br>Chao<br><br>-- <br><div>***********************************************************************************</div>
<div>Chao YUE<br>Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)<br>UMR 1572 CEA-CNRS-UVSQ<br>Batiment 712 - Pe 119<br>91191 GIF Sur YVETTE Cedex</div>
<div>Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16<br></div>

<div>************************************************************************************</div><br>
</font></span><br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br>