[SciPy-dev] feedback on scipy.sparse

Matthieu Brucher matthieu.brucher at gmail.com
Thu Dec 13 07:31:27 EST 2007


>
> > Yes, it should, I think I should go back to sleep...
> > Is there a way to create a sparse matrix from a list of lists directly
> and a
> > separate data array ? Just to know if I have to transform my list of
> lists
> > to the format (row, col).
> >
> > Matthieu
>
> You mean this?
>
> In [3]: row = [0,0,1,1,1]
> In [4]: col = [10,11,50,55,100]
> In [5]: rc = [row, col]
> In [6]: rc
> Out[6]: [[0, 0, 1, 1, 1], [10, 11, 50, 55, 100]]
> In [7]: data = array([1.,2.,1.,3.,4.])
> In [9]: A = sp.coo_matrix((data,rc))
> In [10]: A
> Out[10]:
> <2x101 sparse matrix of type '<type ' numpy.float64'>'
>          with 5 stored elements in COOrdinate format>
>
> In [11]: print A
>    (0, 10)       1.0
>    (0, 11)       2.0
>    (1, 50)       1.0
>    (1, 55)       3.0
>    (1, 100)       4.0


Not exactly.
I have something like :
a = [[0, 2, 5], [3, 4], [4, 2]]
and then some data :
data = [1, 2, 3, 4, 5, 6, 7] or [[1, 2, 3], [4, 5], [6, 7]]and then
the matrix would be :

[[1, 0, 2, 0, 0, 0]
[0, 0, 0, 3, 4, 0]
[0, 0, 7, 0, 6, 0]]

Is there something like this ?

Matthieu
-- 
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://mail.python.org/pipermail/scipy-dev/attachments/20071213/907591a7/attachment.html>


More information about the SciPy-Dev mailing list