title: python numpy weighted average with nans
body: <p>First things first: this is not a duplicate of <a href="https://stackoverflow.com/questions/5480694/numpy-calculate-averages-with-nans-removed">NumPy: calculate averages with NaNs removed</a>, i'll explain why:</p>
  
  <p>Suppose I have an array</p>
  
  <pre><code>a = array([1,2,3,4])
  </code></pre>
  
  <p>and I want to average over it with the weights</p>
  
  <pre><code>weights = [4,3,2,1]
  output = average(a, weights=weights)
  print output
       2.0
  </code></pre>
  
  <p>ok. So this is pretty straightforward. But now I have something like this:</p>
  
  <pre><code>a = array([1,2,nan,4])
  </code></pre>
  
  <p>calculating the average with the usual method yields of course<code>nan</code>. Can I avoid this?
  In principle I want to ignore the nans, so I'd like to have something like this:</p>
  
  <pre><code>a = array([1,2,4])
  weights = [4,3,1]
  output = average(a, weights=weights)
  print output
       1.75
  </code></pre>