title: Dealing with zero's in a moving average
body: <p><strong>EDIT</strong></p>
  
  <p>My original post was not the best explination, so I have rewritten it.</p>
  
  <p>So what I'm trying to do is calculate the moving average on an array of data. Each average is taken over, for example, the 24 values.
  However, I have two conditions that need to be  changed in my current function. </p>
  
  <ul>
  <li>Take an average over 24 values that ARE NOT zero as zero is considered as bad data, so I want 24 'good' values for the average.</li>
  <li>If there are five <strong>consecutive</strong> zeros, I do not want to take the average and simply say the average is zero.</li>
  </ul>
  
  <p>I need to 
  Here is my current function for this, but it needs updating to encompass these changes.</p>
  
  <pre><code>def averaged_rel_track(navg, rel_values, nb):
      '''function to average the relative track values for each blade. This is 
      dependant on the number values specified by the user to average over in a 
      rolling average'''
      avg_rel_track=[]
      for blade in range(0,int(nb)):
          av_values=[]
          rel_blade=rel_values[:,int(blade)]
          for rev in range(0,len(rel_blade)):
              section=rel_blade[rev-int(navg)+1:rev+1]
              print section
              if np.any(section==0):   
                  av_value=0
              else:
                  av_value=np.sum(section)/int(navg)
              print av_value
              av_values.append(av_value)
          avg_rel_track.append(av_values)
      avg_rel_track=np.array(avg_rel_track) 
      return avg_rel_track.transpose()
  </code></pre>
  
  <p>At the moment there is alot of checking involved.</p>
  
  <p>Is there a function where you can select X number of values that are not zero/none? Currently what I'm attempting to do works like this:</p>
  
  <pre><code>Select a section of data than is N values long
  x= number of zeros/nan's in the data
  Extend section by x values
  </code></pre>
  
  <p>But this doesn't work as then I need to check that the new section does not contain zeros and it would detect the original zeros. I could check the extension for zeros, repeating the process, but this seems like a very long winded way to do  this. </p>
  
  <p>I know of <code>scipy.stats.nanmean</code> that will ignore the none values when averaging the data.</p>
  
  <p>If anyone could help that would be great, but the main question I would like advice on is:</p>
  
  <blockquote>
    <p>Is there a function that will select N values that are not zero or one?</p>
  </blockquote>