title: numpy.any(axis=i) for scipy.sparse
body: <pre class="lang-py prettyprint-override"><code>import numpy
  a = numpy.array([
      [0, 1, 0, 0],
      [1, 0, 0, 0],
      [0, 0, 1, 0],
      [0, 0, 0, 0],
      [0, 0, 0, 0],
  ])
  numpy.any(a, axis=0)
  numpy.any(a, axis=1)
  </code></pre>
  <p>produces</p>
  <pre><code>array([ True,  True,  True, False])
  array([ True,  True,  True, False, False])
  </code></pre>
  <p>However, after</p>
  <pre><code>from scipy import sparse
  a = sparse.csr_matrix(a)
  </code></pre>
  <p>the same <code>numpy.any(a, axis)</code> calls produces</p>
  <pre><code>&lt;5x4 sparse matrix of type '&lt;class 'numpy.intc'&gt;'
          with 3 stored elements in Compressed Sparse Row format&gt;
  </code></pre>
  <p>and</p>
  <pre><code>Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
    File &quot;&lt;__array_function__ internals&gt;&quot;, line 5, in any
    File &quot;C:\Users\user\.conda\envs\py385\lib\site-packages\numpy\core\fromnumeric.py&quot;, line 2330, in any
      return _wrapreduction(a, np.logical_or, 'any', axis, None, out, keepdims=keepdims)
    File &quot;C:\Users\user\.conda\envs\py385\lib\site-packages\numpy\core\fromnumeric.py&quot;, line 87, in _wrapreduction
      return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
  numpy.AxisError: axis 1 is out of bounds for array of dimension 0
  </code></pre>
  <p>Of course, <code>a</code> is actually so large a sparse matrix that converting to normal <code>numpy</code> array is not an option.  How can I acquire the same (or equivalent) result for a <code>csr_matrix</code> and other <code>scipy.sparse</code> matrices?</p>
  <p><strong>ADDED:</strong></p>
  <p>According to <a href="https://docs.scipy.org/doc/scipy/reference/sparse.html#usage-information" rel="nofollow noreferrer">Usage information in official scipy documentation</a>,</p>
  <blockquote>
  <p>Despite their similarity to NumPy arrays, it is <strong>strongly discouraged</strong> to use NumPy functions directly on these matrices because NumPy may not properly convert them for computations, leading to unexpected (and incorrect) results. If you do want to apply a NumPy function to these matrices, first check if SciPy has its own implementation for the given sparse matrix class, or <strong>convert the sparse matrix to a NumPy array</strong> (e.g., using the <em>toarray()</em> method of the class) first before applying the method.</p>
  </blockquote>
  <p>I'm looking for &quot;its own implementation&quot; or equivalent.</p>