From: Dominique O. <dom...@gm...> - 2009-09-13 23:49:57
|
On Fri, Sep 4, 2009 at 8:09 AM, Jose Blanca<jb...@bt...> wrote: > Hi: > I'm new to pyparse, thanks for doing this tool open source. > I'm trying to store an sparse vector and to get the results. My requirements > a quite simple I just need to store some items and to get them at the end of > the analysis. > I've created the matrix with: > vect = pysparse.spmatrix.ll_mat(nelements, 1, size_hint) > > And now I want to get the items from the matrix. I could do: > items = vect.items() > > The problem is that the created items is a list not an iterator. That consumes > a lot of extra memory just to access the matrix. Is this the expected > behaviour or am I missing something? Hi Jose, Sorry for the late reply. Pysparse objects are not iterable and weren't really designed to store vectors (although they obviously can) but large sparse matrices. As Lukasz suggested, you can use find() to get the values in triple format as Numpy arrays and iterate through those. However, you may find it more convenient to simply store your sparse vector in a dictionary and iterate through the list of items. -- Dominique |