title: How can I ignore zeros when I take the median on columns of an array?
body: <p>I have a simple numpy array. </p>
  
  <pre><code>array([[10,   0,  10,  0],
         [ 1,   1,   0,  0]
         [ 9,   9,   9,  0]
         [ 0,  10,   1,  0]])
  </code></pre>
  
  <p>I would like to take the median of each column, individually, of this array. </p>
  
  <p>However, there are a few <code>0</code> values in various places which I would like to ignore in the calculation of the medians.</p>
  
  <p>To further complicate, I would like to keep the columns with only <code>0</code> entries as having the median of <code>0</code>.  In this manner, those columns would serve as a bit of a place holder, keeping the dimensions of the matrix the same.</p>
  
  <p>The numpy documentation doesn't have any argument that would work for what I want (maybe I am spoiled by the many switches we get with R!)  </p>
  
  <p><code>numpy.median(a, axis=None, out=None, overwrite_input=False)[source]</code></p>
  
  <p>Can someone please shed some light on an effective way to do this, which is in line with the spirit of numpy?  I could hack it out but in that case I feel like I've defeated the purpose of using numpy in the first place.</p>
  
  <p>Thanks in advance.</p>