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. Thanks, Ryan
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
Perfect. Thanks Travis. On 2/17/06, Travis Oliphant <oliphant.travis@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@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user
Actually, I may have a small problem in that nls.sqrt cannot take a vector input. On 2/17/06, Ryan Krauss <ryanlists@gmail.com> wrote:
Perfect. Thanks Travis.
On 2/17/06, Travis Oliphant <oliphant.travis@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@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user
Ryan Krauss wrote:
Actually, I may have a small problem in that nls.sqrt cannot take a vector input.
It originally did when it was in scipy_base. I'm not sure why it changed. I'll look in to it. It's supposed to take an array. -Travis
participants (3)
-
Christian Kristukat -
Ryan Krauss -
Travis Oliphant