[SciPy-User] what is linsolve? sparse docs
Sun Oct 24 14:26:08 CDT 2010
On Sun, Oct 24, 2010 at 1:09 PM, <email@example.com> wrote:
> (from a question on ask.scipy.org)
> The docs for scipy sparse
> 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
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]
# 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User