[SciPy-user] element by element multiplication and round off

Ryan Krauss ryanfedora at comcast.net
Tue Aug 2 13:03:04 CDT 2005


I have a vector of imaginary numbers that I need to square and do 
somethings element-by-element.  If I simply do
In [55]: test=svect**2
In [56]: test[-1]
Out[56]: (-96731.992735076812+1.1845861292127511e-011j)
I get round off error.

But if I do it element-by-element in a for loop the problem goes away:
In [57]: test2=svect[-1]**2
In [58]: test2
Out[58]: (-96731.992735076812+0j)

Or
In [59]: sqout=[]

In [60]: for ent in svect.tolist():
   ....:     curent=ent**2
   ....:     sqout.append(curent)
   ....:
In [61]: test2=array(sqout)

In [62]: test2[-1]
Out[62]: (-96731.992735076812+0j)

Why is this and can I get rid of the round off without having to write 
for loops for everything?

Thanks,

Ryan



More information about the SciPy-user mailing list