[SciPy-user] casting complex numbers
Travis Oliphant
oliphant.travis at ieee.org
Fri Feb 17 00:55:33 CST 2006
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
More information about the SciPy-user
mailing list