thanks. Olivier. I see.<br><br>Chao<br><br><div class="gmail_quote">2011/10/18 Olivier Delalleau <span dir="ltr"><<a href="mailto:shish@keba.be">shish@keba.be</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
As far as I can tell ma.mean() is working as expected here: it computes the mean only over non-masked values.<br>If you want to get rid of any mean that was computed over a series containing masked value you can do:<br><br>

b = a.mean(0)<br>b.mask[a.mask.any(0)] = True<br><br>Then b will be:<br><br>masked_array(data = [5.0 -- -- 8.0 9.0 -- 11.0 12.0 -- 14.0],<br>             mask = [False  True  True False False  True False False  True False],<br>

       fill_value = 1e+20)<br><br>-=- Olivier<br><br><div class="gmail_quote">2011/10/18 Chao YUE <span dir="ltr"><<a href="mailto:chaoyuejoy@gmail.com" target="_blank">chaoyuejoy@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div class="h5">
Dear all,<br><br>previoulsy I think np.ma.mean() will automatically filter the masked (missing) value but it's not?<br>In [489]: a=np.arange(20.).reshape(2,10)<br><br>In [490]: a=np.ma.masked_array(a,(a==2)|(a==5)|(a==11)|(a==18),fill_value=np.nan)<br>


<br>In [491]: a<br>Out[491]: <br>masked_array(data =<br> [[0.0 1.0 -- 3.0 4.0 -- 6.0 7.0 8.0 9.0]<br> [10.0 -- 12.0 13.0 14.0 15.0 16.0 17.0 -- 19.0]],<br>             mask =<br> [[False False  True False False  True False False False False]<br>


 [False  True False False False False False False  True False]],<br>       fill_value = nan)<br><br>In [492]: a.mean(0)<br>Out[492]: <br>masked_array(data = [5.0 1.0 12.0 8.0 9.0 15.0 11.0 12.0 8.0 14.0],<br>             mask = [False False False False False False False False False False],<br>


       fill_value = 1e+20)<br><br>In [494]: np.ma.mean(a,0)<br>Out[494]: <br>masked_array(data = [5.0 1.0 12.0 8.0 9.0 15.0 11.0 12.0 8.0 14.0],<br>             mask = [False False False False False False False False False False],<br>


       fill_value = 1e+20)<br><br>In [495]: np.ma.mean(a,0)==a.mean(0)<br>Out[495]: <br>masked_array(data = [ True  True  True  True  True  True  True  True  True  True],<br>             mask = False,<br>       fill_value = True)<br>


<br>only use a.filled().mean(0) can I get the result I want:<br>In [496]: a.filled().mean(0)<br>Out[496]: array([  5.,  NaN,  NaN,   8.,   9.,  NaN,  11.,  12.,  NaN,  14.])<br><br>I am doing this because I tried to have a small fuction from the web to do moving average for data:<br>


<br>import numpy as np<br>def rolling_window(a, window):<br>    if window < 1:<br>        raise ValueError, "`window` must be at least 1."<br>    if window > a.shape[-1]:<br>        raise ValueError, "`window` is too long."<br>


    shape = a.shape[:-1] + (a.shape[-1] - window + 1, window)<br>    strides = a.strides + (a.strides[-1],)<br>    return np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides) <br><br>def move_ave(a,window):<br>


    temp=rolling_window(a,window)<br>    pre=int(window)/2<br>    post=int(window)-pre-1<br>    return np.concatenate((a[...,0:pre],np.mean(temp,-1),a[...,-post:]),axis=-1)<br><br><br>In [489]: a=np.arange(20.).reshape(2,10)<br>


<br>In [499]: move_ave(a,4)<br>Out[499]: <br>masked_array(data =<br> [[  0.    1.    1.5   2.5   3.5   4.5   5.5   6.5   7.5   9. ]<br> [ 10.   11.   11.5  12.5  13.5  14.5  15.5  16.5  17.5  19. ]],<br>             mask =<br>


 False,<br>       fill_value = 1e+20)<br><br>thanks,<br><br>Chao<br clear="all"><font color="#888888"><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><br></div></div>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">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>
<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><br clear="all"><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>