[Numpy-discussion] Problem with roots and complex coefficients

lorenzo bolla lbolla@gmail....
Thu Apr 19 10:34:53 CDT 2007


dear all,
I've some problems with numpy.roots.
take a look at the following code:

========================================
import numpy

OK = numpy.roots([1, 1, 1])
OK = numpy.roots([1j, 1])
KO = numpy.roots([1, 1j, 1])
========================================

it fails with this error message, trying to execute the last line:

TypeError: can't convert complex to float; use
abs(z)/usr/lib/python2.4/site-packages/numpy/lib/polynomial.py in roots(p)
    119     if N > 1:
    120         # build companion matrix and find its eigenvalues (the
roots)
--> 121         A = diag(NX.ones((N-2,), p.dtype), -1)
    122         A[0, :] = -p[1:] / p[0]
    123         roots = _eigvals(A)

/usr/lib/python2.4/site-packages/numpy/lib/twodim_base.py in diag(v, k)
     66             i = arange(0,n+k)
     67             fi = i+(i-k)*n
---> 68         res.flat[fi] = v
     69         return res
     70     elif len(s)==2:

TypeError: can't convert complex to float; use abs(z)

any ideas?
thanks,
Lorenzo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070419/86ac5516/attachment.html 


More information about the Numpy-discussion mailing list