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

lorenzo bolla lbolla at gmail.com
Thu Apr 3 05:25:49 EDT 2008


your function gij returns a 2d array (a matrix) with just 1 element.
you cannot assign to the element b[0,0], the value of the matrix c, but you
can assign it the value of the _only_ element of c, i.e. c.item().

your last line become:
b[0,0] = c.item()

hth,
L.

On Thu, Apr 3, 2008 at 4:22 AM, chengbo duan <lilyphysik at gmail.com> wrote:

> 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)
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>


-- 
Lorenzo Bolla
lbolla at gmail.com
http://lorenzobolla.emurse.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20080403/cbd061d2/attachment.html>


More information about the SciPy-User mailing list