[SciPy-dev] sparse matrix indexing (__getitem__ or not?)
Robert Cimrman
cimrman3@ntc.zcu...
Mon Sep 10 03:02:07 CDT 2007
Hi,
I have added a function to fill in the gap in the CSR matrix indexing
capabilities into sparsetools. It extracts a submatrix (makes a new
matrix) using row and column slices. For the moment it has been made
accessible by adding a new method get_submatrix( self, slice0, slice1 )
to csr_matrix class - the method returns a new matrix and not a view, as
indexing via [] (__getitem__()) currently does. Note that it could be
easily extended for general indexing by index arrays.
It is not possible for a sparse matrix to return a view of a general
submatrix, therefore I would like to discuss here which of the following
two possibilities suit the other sparse matrix users better:
1. __getitem__() returns views only, other submatrix extraction
functionality is accessed via another method (e.g. get_submatrix()).
This case is compatible with the behaviour of dense arrays, but IMHO a
bit clumsy.
2. __getitem__() returns views or new matrices as necessary (properly
documented for each sparse matrix kind). This case differs in behaviour
from the dense arrays but, pragmatically, I like this case more.
As a side-note, even if the second item gets implemented, I see a niche
for the get_submatrix() method - it could have additional arguments
specifying for example that it should return a dense array instead of
the sparse one.
r.
More information about the Scipy-dev
mailing list