|
From: Daniel W. <dan...@gm...> - 2008-06-17 15:09:18
|
On Tue, Jun 17, 2008 at 5:33 AM, Artur Palha <art...@gm...> wrote:
> Hi to you all, I hope someone can help me.
>
> I am trying to do the following with pysparse but I am having problems doing it.
>
> I have a dense vector, say:
>
> x = numpy.arange(0,10)
>
> and a sparse matrix:
>
> A = pysparse.spmatrix.ll_mat(10,10)
>
> What I wish to do is:
>
> x = x + A[:, 2]
>
> But this gives the following error:
> TypeError: unsupported operand type(s) for +: 'float' and 'll_mat'
If I remember correctly, ll_mat would need to have the __iter__ method
to work with numpy. numpy checks the type of ll_mat then looks for one
of __getitem__, __iter__, __array__ or __add__. I don't think ll_mat
has these. The code I use has a wrapper which makes pysparse more
pythonic. You may prefer to use the wrapper if it suits your purposes.
<http://matforge.org/fipy/browser/trunk/fipy/tools/pysparseMatrix.py>
>
> Then I tried like this:
>
> x = numpy.arange(0,10)
>
> A = pysparse.sparray.sparray((10,10))
>
> With this it works ok but then, when I try to do a slice:
>
> A_reduced = A[0:5, 0:5]
>
> It gives an error:
> TypeError: unsupported operand type(s) for +: 'int' and 'slice'
Not sure about why this doesn't work. It was probably implemented and
never tested properly. I don't believe it does anything useful
anyway.
> Anybody can give a help?
>
> Also, what is the main difference between spmatrix and sparray?
I would avoid using sparray. You also might want to check out scipy as
their sparse support is much better now.
--
Daniel Wheeler
|