# [SciPy-User] what is linsolve? sparse docs

Warren Weckesser warren.weckesser@enthought....
Sun Oct 24 14:26:08 CDT 2010

```On Sun, Oct 24, 2010 at 1:09 PM, <josef.pktd@gmail.com> wrote:

> (from a question on ask.scipy.org)
>
> The docs for scipy sparse
>
> http://docs.scipy.org/doc/scipy/reference/sparse.html?highlight=linsolve
>
> contain an example that imports linsolve.
>
> I cannot find anything like this. Is this a historical artifact or
> some hidden module somewhere ?
>
> Can someone who knows this update the examples?
>

I just updated scipy/sparse/info.py, which is where this documentation comes
from.  That file was last touched three years ago, and there have been
changes in the source code since then.

Here's a script containing the same code as in updated "Example 1" of that
docstring:

-----
from scipy.sparse import lil_matrix
from scipy.sparse.linalg import spsolve
from numpy.linalg import solve, norm
from numpy.random import rand

A = lil_matrix((1000, 1000))
A[0, :100] = rand(100)
A[1, 100:200] = A[0, :100]
A.setdiag(rand(1000))

# Now convert it to CSR format and solve A x = b for x:

A = A.tocsr()
b = rand(1000)
x = spsolve(A, b)

# Convert it to a dense matrix and solve, and check that the result
# is the same:

x_ = solve(A.todense(), b)

# Now we can compute norm of the error with:

err = norm(x-x_)
print err < 1e-10
-----

Warren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20101024/a98fe122/attachment.html
```