[SciPy-user] More problems with Sparse

Robert Kern rkern at ucsd.edu
Wed Oct 27 02:16:12 CDT 2004


Nils Wagner wrote:
> Hi Travis,
> 
> A few days ago I have reported on the following bug in sparse. (recent 
> Bug tracker entries)
> It would be nice if this problem could be fixed.
> Thanks in advance.
> 
> Nils
> 
>>>> from scipy import *
>>>> A = sparse.dok_matrix()
>>>> A[0,0] = 1j
>>>> A.todense()
> 
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>  File "/usr/lib/python2.3/site-packages/scipy/sparse/Sparse.py", line 
> 1326, in todense
>    new[ikey0,ikey1] = self[key]
> TypeError: can't convert complex to float; use abs(z)

It's difficult to determine beforehand if a matrix needs to be complex 
or not. The default typecode for the dense array is 'd' (double 
precision real). Use the typecode keyword argument to todense() to 
choose something else.

E.g.

   A.todense(Complex)

I found this out in 30 seconds by looking at the source code.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter



More information about the SciPy-user mailing list