# [SciPy-user] Complex sparse support

Nils Wagner nwagner@iam.uni-stuttgart...
Fri Feb 15 15:24:47 CST 2008

```On Fri, 15 Feb 2008 12:21:16 -0800 (PST)
<kc106_2005-scipy@yahoo.com> wrote:
> Hi all,
>
> I am evaluating scipy to see if it can help me.  I saw
> this message:
>
> http://aspn.activestate.com/ASPN/Mail/Message/scipy-user/3365806
>
> and read the subsequent responses.  Not knowing
> anything about scipy, does that means the complex
> sparse matrix part is buggy?
>
> Does anybody has a working sample to show that how to
> make it works?
>
> Regards,
>
> --
> John Henry
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

If you have installed numpy, scipy via svn you can try
the following

from scipy import sparse
from scipy.splinalg import spsolve, use_solver
from numpy import linalg
from numpy.random import rand
A = sparse.lil_matrix((500, 500))
A[0, :100] = rand(100)+rand(100)*1j
A[1, 100:200] = A[0, :100]
A.setdiag(rand(500)+1j*rand(500))
A = A.tocsr()
b = rand(500)
x = spsolve(A, b)
x_ = linalg.solve(A.todense(), b)
err = linalg.norm(x-x_)
print err < 1e-10, err

from pylab import spy, show
spy(A.todense())
show()

Nils
```