[SciPy-user] math operations on sparse matrices
Sat Feb 21 22:12:58 CST 2009
On Sat, Feb 21, 2009 at 10:50 PM, Nathan Bell <firstname.lastname@example.org> wrote:
> On Sat, Feb 21, 2009 at 8:33 PM, <email@example.com> wrote:
>> That was also my first guess, however
>> <50x50 sparse matrix of type '<type 'numpy.float64'>'
>> with 208 stored elements in Dictionary Of Keys format>
>> Traceback (most recent call last):
>> File "<pyshell#78>", line 1, in <module>
>> File "\Programs\Python25\Lib\site-packages\scipy\sparse\base.py",
>> line 429, in __getattr__
>> AttributeError: data not found
> Note the .tocsr() in the first step:
>>>> M = M.tocsr()
>>>> M.data = np.exp(M.data)
>> From the graphical results it seems to work, but since this is my
>> first try with scipy.sparse.linalg, I'm not sure what the methods to
>> in detail.
> You'll want to convert to CSR (or CSC) before calling those solvers
> anyway. CSR/CSC offer much faster matrix-vector products, the main
> cost in most iterative methods.
Yes, thanks after your message, I started to compare both formats and
the is a big time difference csr is much faster. I had used dok,
because that's what I got from spatial.
I started to increase my test size and I am working now with a
distance matrix of 10000 by 10000, and the solver seems to work pretty
well. Initially, I was worried about the LinearOperator because I
wasn't sure what the solution means when I transform a sparse distance
matrix. But the graphs look good, so, I guess, it works.
With scipy.spatial and scipy.sparse it's pretty quick to write a large
scale regression problem like this.
More information about the SciPy-user