title: Why does np.median() return multiple rows?
body: <p>I have a numpy array which has 100 rows and 16026 columns. I have to find the median of every column. So median for every column will be calculated from 100 observations (100 rows in this case). I am using the following code to achieve this:</p>
  
  <pre><code>for category in categories:
      indices = np.random.randint(0, len(os.listdir(filepath + category)) - 1, 100)
      tempArray = X_train[indices, ]
      medArray = np.median(tempArray, axis=0)
      print(medArray.shape)
  </code></pre>
  
  <p>And here's the output that I get:</p>
  
  <pre><code>(100, 16026)
  (100, 16026)
  (100, 16026)
  (100, 16026)
  </code></pre>
  
  <p>My question is - why is the shape of <code>medArray</code> 100*16026 and not 1*16026? Because I am calculating the median of every column, I would expect only one row with 16026 columns. What am I missing here? </p>
  
  <p>Please note that <code>X_train</code> is a sparse matrix.</p>
  
  <pre><code>X_train.shape
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>(2034, 16026)
  </code></pre>
  
  <p>Any help in this regard is much appreciated.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>The above problem has been solved by <code>toarray()</code> function.</p>
  
  <pre><code>tempArray = X_train[indices, ].toarray()
  </code></pre>
  
  <p><strong>I also figured that I was being stupid and also including all the zeroes in my median calculation and that's why I was getting 0 as the median all the time. Is there an easy way of calculating the median by removing/ignoring the zeroes across all the columns?</strong></p>