Extremely slow scipy.sparse lil_diags - any walkaround?
The following script takes 26 sec on my computer and consumes several hundreds MB RAM. from numpy import ones from time import time import scipy.sparse as SP N = 10**6 a =ones(N) t = time() SP.lil_diags([a], [0], (N,N)) print('time elapsed: ' + str(time()-t)) Can I somehow in other way create a scipy.sparse format matrix from the single diagonal? Thank you in advance, D.
Try constructing the matrix using dok_matrix or coo_matrix, then converting to csr or csc. I've found it helpful to look at the source code as the documentation is not always complete and accurate. Jason 2011/1/28 Dmitrey <tmp50@ukr.net>
The following script takes 26 sec on my computer and consumes several hundreds MB RAM.
from numpy import ones from time import time import scipy.sparse as SP N = 10**6 a =ones(N) t = time() SP.lil_diags([a], [0], (N,N)) print('time elapsed: ' + str(time()-t))
Can I somehow in other way create a scipy.sparse format matrix from the single diagonal? Thank you in advance, D.
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
-- Jason Rennie Research Scientist, ITA Software 617-714-2645 http://www.itasoftware.com/
On Fri, Jan 28, 2011 at 9:05 AM, Jason Rennie <jrennie@gmail.com> wrote:
Try constructing the matrix using dok_matrix or coo_matrix, then converting to csr or csc. I've found it helpful to look at the source code as the documentation is not always complete and accurate.
the source of spdiags shows that there is also a diag_matrix class/format csr looks fast, diag returns immediately
n 1000000 a=sparse.spdiags(np.arange(10**6),0,n,n, format='csr') b=sparse.dia_matrix( (np.arange(n),0), shape=(n,n))
Josef
Jason
2011/1/28 Dmitrey <tmp50@ukr.net>
The following script takes 26 sec on my computer and consumes several hundreds MB RAM.
from numpy import ones from time import time import scipy.sparse as SP N = 10**6 a =ones(N) t = time() SP.lil_diags([a], [0], (N,N)) print('time elapsed: ' + str(time()-t))
Can I somehow in other way create a scipy.sparse format matrix from the single diagonal? Thank you in advance, D.
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
-- Jason Rennie Research Scientist, ITA Software 617-714-2645 http://www.itasoftware.com/
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
participants (3)
-
Dmitrey
-
Jason Rennie
-
josef.pktd@gmail.com