[SciPy-user] casting complex numbers

Ryan Krauss ryanlists at gmail.com
Fri Feb 17 09:33:20 EST 2006


Perfect.  Thanks Travis.

On 2/17/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
> Ryan Krauss wrote:
>
> >Is there a way to make python return a complex number number instead
> >of nan when taking the sqrt of a negative float?  I have an
> >automatically generated function based on Maxima symbolic output that
> >is giving bad output because of this.  Basically, part of the symoblic
> >expression includes sqrt(-s**2*x) where s is complex and this
> >expression would evaluate nicely in python.  For whatever reason,
> >Maxima prefers to output this expression as sqrt(-x)*s, which would
> >also evaluate correctly if sqrt(-x) gave 1.0j*sqrt(x), but since x is
> >a float it is returning nan.  I am hoping for flag similar to from
> >__future__ import division instead of having to declare all my
> >variables as complex.
> >
> >
> >
> import numpy.lib.scimath as nls
>
> nls.sqrt(-1)
>
> -Travis
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
>




More information about the SciPy-User mailing list