[SciPy-User] indexation of sparse matrices

Nathan Bell wnbell at gmail.com
Mon Dec 14 01:39:03 EST 2009


On Sun, Dec 13, 2009 at 12:34 PM, Emmanuelle Gouillart
<emmanuelle.gouillart at 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 at gmail.com
http://www.wnbell.com/



More information about the SciPy-User mailing list