title: Slicing a scipy.sparse.lil_matrix in rows and columns
body: <p>I would like to extract specific rows and columns from a scipy sparse matrix - probably <code>lil_matrix</code> will be the best choice here.</p>
  
  <p>It works fine here:</p>
  
  <pre><code>from scipy import sparse
  lilm=sparse.lil_matrix((10,10))
  lilm[0:4,0:3]
  </code></pre>
  
  <p>This returns a 4x3 sparse matrix. I don't want a block from the matrix though, but rather single columns and rows. I'd expect this to work:</p>
  
  <pre><code>lilm[[1,2,3],[4,5,6]]
  </code></pre>
  
  <p>but it returns a 1x3 sparse matrix. This also doesn't work with numpy arrays, but there you can use numpy.ix_, as described in <a href="https://stackoverflow.com/questions/4257394/slicing-of-a-numpy-2d-array-or-how-do-i-extract-an-mxm-submatrix-from-an-nxn-ar">Slicing of a NumPy 2d array, or how do I extract an mxm submatrix from an nxn array (n&gt;m)?</a>.</p>
  
  <p>How can one accomplish this behaviour with a <code>lil_matrix</code>?</p>
  
  <p>My question is partly answered in <a href="https://stackoverflow.com/questions/7609108/slicing-sparse-scipy-matrix/7610298#7610298">slicing sparse (scipy) matrix</a>, but I couldn't get this to work for <code>lil_matrix</code>.</p>