[SciPy-user] TypeError: can't convert complex to float; use abs(z)

chengbo duan lilyphysik@gmail....
Wed Apr 2 21:22:15 CDT 2008


Hi,guys

I  encountered  this error message in other place,then I simplify the code
and paste it and the output messages in the end of the letter .
The output of the variable "c" confirm that the kind of  "c" is complex,the
kind of  "b" is also complex,there is no need to convert  complex  to
float.So I 'm confused with this message,Any suggestion?

Thanks in advance
Abo

#!/usr/bin/env python
#coding=utf-8
from scipy import *
def gij(vi,vj,mat):
    i=size(vi,0)*size(vi,1)
    st= dot(reshape(conjugate(vi),(1,i)),dot(mat,reshape(vj,(i,1))))
    return st
a=zeros((2,2),dtype=complex128)
b=zeros((2,2),dtype=complex128)
z=1.0j
sign=-1.0
vi=zeros((2,1),dtype=complex128)
vj=zeros((2,1),dtype=complex128)
vi=[[1.0+0.5j],[1.0+0.5j]]
vj=copy(vi)
a=1.0+1.0j
c=gij(vi,vj,a)
print "c=",c
b[0,0]=c

> "C:\Python25\python.exe" -u "C:\work\complex.py"
c= [[ 2.5+2.5j]]
Traceback (most recent call last):
  File "C:\work\complex.py", line 19, in <module>
    b[0,0]=c
TypeError: can't convert complex to float; use abs(z)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080403/ba0f3909/attachment-0001.html 


More information about the SciPy-user mailing list