title: Conditional average with numpy
body: <p>Given a 2x3 array, I want to calculate the average on <code>axis=0</code>, but only considering values that are larger than 0.</p>
  
  <p>So given the array</p>
  
  <pre><code>[ [1,0],
    [0,0],
    [1,0] ]
  </code></pre>
  
  <p>I want the output to be</p>
  
  <pre><code># 1, 0, 1 filtered for &gt; 0 gives 1, 1, average = (1+1)/2 = 1
  # 0, 0, 0 filtered for &gt; 0 gives 0, 0, 0, average = 0    
  [1 0]
  </code></pre>
  
  <p>My current code is</p>
  
  <pre><code>import numpy as np
  
  frame = np.array([ [1,0],
                     [0,0],
                     [1,0] ])
  
  weights=np.array(frame)&gt;0
  
  print("weights:")
  print(weights)
  
  print("average without weights:")
  print((np.average(frame, axis=0)))
  
  print("average with weights:")
  print((np.average(frame, axis=0, weights=weights)))
  </code></pre>
  
  <p>This gives me</p>
  
  <pre><code>weights:
  [[ True False]
   [False False]
   [ True False]]
  average without weights:
  [ 0.66666667  0.        ]
  average with weights:
  Traceback (most recent call last):
  File "C:\Users\myuser\project\test.py", line 123, in &lt;module&gt;
  print((np.average(frame, axis=0, weights=weights)))
  File "C:\Users\myuser\Miniconda3\envs\myenv\lib\site-packages\numpy\lib\function_base.py", line 1140, in average
  "Weights sum to zero, can't be normalized")
  ZeroDivisionError: Weights sum to zero, can't be normalized
  </code></pre>
  
  <p>I don't understand this error. What am I doing wrong and how can I get the average for all values greater than zero along <code>axis=0</code>? Thanks!</p>