[SciPy-dev] better sparse slicing
Robert Cimrman
cimrman3@ntc.zcu...
Thu Feb 14 03:15:23 CST 2008
Nathan Bell wrote:
> I've expanded on Robert C's earlier efforts in improving the state of
> sparse slicing.
>
> Previously you could do
> A[1]
> A[1:2]
> A[1:2,1]
> A[1:2,1:2]
>
> Now you can do:
> A[[1,2]]
> A[1:2,[1,2]]
> A[[1,2],1:2]
> A[[1,2],[1,2]]
Great!
> and the all important:
> A[[1,2],:][:,[1,2]]
This needs some more range checking...
In [3]: a = sp.csr_matrix( [[1,0,1,0],[0,1,2,3]] )
In [5]: print a
(0, 0) 1
(0, 2) 1
(1, 1) 1
(1, 2) 2
(1, 3) 3
In [6]: a[[1,2],:][:,[1,2]]
Segmentation fault
>
> Currently this only works for csr_matrix (and not csc_matrix). Once I
> trust my csr_matrix implementation I'll make csc_matrix work also.
> The above operations should mimic numpy.matrix exactly.
Many thanks for this, Nathan.
r.
More information about the Scipy-dev
mailing list