[SciPy-user] How to get sqrt(-1) = 1j per default?

Xavier Gnata xavier.gnata@gmail....
Sat Jul 11 16:56:00 CDT 2009


outch!

numpy.sqrt(-1)
nan

scipy.sqrt(-1)
1j

IMHO, it should behave the same way.
Python provides us with math and cmath.
It is a bit strange from a mathematical point of view but it is 
perfectly valid from a computer science point of view.

Why numpy.sqrt(-1)!=scipy.sqrt(-1) ??
I know it would be hard to change that now...but still.

Xavier


> In an "ipython -pylab -p scipy" console I get
> In [1]: sqrt(-1)
> Out[1]: nan
> but I would prefer 1j as the result. This is achieved by
> In [2]: from scipy import *
> After that I get
> In [3]: sqrt(-1)
> Out[3]: 1j
>
> I found out that the ipython option -p scipy executes the startup script
> Python25\Lib\site-packages\IPython\Extensions\ipy_profile_scipy.py
> which contains
>
>     ip = IPython.ipapi.get()
>
>     try:
>         ip.ex("import math,cmath")
>         ip.ex("import numpy")
>         ip.ex("import scipy")
>
>         ip.ex("import numpy as np")
>         ip.ex("import scipy as sp")
>     
>         ip.ex("from numpy import *")
>         ip.ex("from scipy import *")
>         print('... import * done')
>
> Here the command "from scipy import *" is the last executed command as in my 
> interactive session above. Why is this startup script not sufficient to have 
> sqrt(-1)=1j right from the console start??
> What I should do additionally to achieve this?
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>   



More information about the SciPy-user mailing list