[SciPy-User] indexation of sparse matrices

Nathan Bell wnbell@gmail....
Mon Dec 14 00:39:03 CST 2009

On Sun, Dec 13, 2009 at 12:34 PM, Emmanuelle Gouillart
<emmanuelle.gouillart@normalesup.org> wrote:
>        Hi Dmitrey,
>        what you want to do is called *fancy indexing* in numpy.  Fancy
> indexing consists in indexing an array with (a) sequence(s) of indices,
> see
> http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing
> for more details. It works on numpy arrays as well as sparse matrices for
> the lil_matrix format. Here is an example:
>        The lil_matrix is meant for supporting fancy indexing, but it is
> not efficient for matrices operations such as inversion or
> multiplication; you should transform your matrix to another format for
> performing such operations.

The CSR and CSC formats also support fast fancy indexing.  Something like:
  >>> A = ... some sparse matrix
  >>> csr_matrix(A)[I,J]
ought to work well.

Nathan Bell wnbell@gmail.com

More information about the SciPy-User mailing list