[SciPy-user] lil_matrix

Giovanni Samaey giovanni.samaey@cs.kuleuven...
Tue Dec 4 05:05:14 CST 2007


Hi all,

I have "solved" the issue by writing

B[:5,:5]=A.tocsr()

This fills up B correctly.  However, this approach appears to be very  
inefficient. (Obviously, I am using *much* larger values than 5.)
It seems that this inefficiency is not due to the conversion but due  
to the filling up of B.  This deduction is made based on the fact that  
adding two lil matrices returns a csr matrix in only a fraction of the  
time the above operation takes.

I am using this approach because I have a very large matrix A in  
sparse format and I want to add a border (and extra row and column).

Any help would be appreciated.

Best,

Giovanni

On 30 Nov 2007, at 18:26, Giovanni Samaey wrote:

> Hello all,
>
> I have a basic question concerning lil_matrix slice assignments.
> The following code does not behave as intended :
>
> import scipy.sparse as S
>
> A = S.lil_matrix((5,5))
> A.setdiag(ones(5))
> B = S.lil_matrix((6,6))
> B[:5,:5]=A
> B.getnnz()
>
> This returns 0 instead of the expected 5.  Am I using the code
> incorrectly ?
>
> Giovanni
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list