[SciPy-user] math operations on sparse matrices

Nathan Bell wnbell@gmail....
Sat Feb 21 21:50:29 CST 2009

On Sat, Feb 21, 2009 at 8:33 PM,  <josef.pktd@gmail.com> wrote:
> That was also my first guess, however
>>>> M
> <50x50 sparse matrix of type '<type 'numpy.float64'>'
>        with 208 stored elements in Dictionary Of Keys format>
>>>> M.data
> Traceback (most recent call last):
>  File "<pyshell#78>", line 1, in <module>
>    M.data
>  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.

Nathan Bell wnbell@gmail.com

More information about the SciPy-user mailing list