[SciPy-dev] feedback on scipy.sparse

Matthieu Brucher matthieu.brucher@gmail....
Thu Dec 13 03:40:23 CST 2007


I thought I would use csr or csc as every row and column will have some
values, but not the same each time, so I don't think that coo is what I
need. But I will try lil when I have some time.

Matthieu

2007/12/13, Nathan Bell <wnbell@gmail.com>:
>
> On Dec 12, 2007 4:03 AM, Stefan van der Walt <stefan@sun.ac.za> wrote:
> > > I'd like to know if some fancy indexing will be available soon. I
> explain
> > > myself. I need to populate a sparse matrix with some weights for each
> line. I'd
> > > like to do s[i, indices] = weights but it does not seem to work. I
> could use a
> > > loop, but it would be slower and this is not acceptable (as it is
> possible to
> > > do so in Matlab).
> >
> > The lil_matrix is used to construct matrices like that:
>
> Matthieu, if you know all the row and column indices and their
> corresponding values then you can use the coo_matrix format like this:
>
> In [1]: from scipy import *
> In [2]: from scipy.sparse import *
> In [3]: row = array([0,1,2,2,1])
> In [4]: col = array([1,2,0,1,1])
> In [5]: data = array([1,2,3,4,5])
> In [6]: A = coo_matrix((data,(row,col)),dims=(3,3))
> In [7]: A.todense()
> Out[7]:
> matrix([[0, 1, 0],
>         [0, 5, 2],
>         [3, 4, 0]])
>
>
> Using COO in this manner should be 10x-100x faster than LIL.  LIL and
> DOK are the only options that allow efficient insertion into a sparse
> matrix, however if you know all the entries a priori then COO is much
> faster.
>
> --
> Nathan Bell wnbell@gmail.com
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-dev
>



-- 
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-dev/attachments/20071213/60556655/attachment.html 


More information about the Scipy-dev mailing list