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

Xavier Gnata xavier.gnata at gmail.com
Sun Jul 12 17:32:11 EDT 2009


Robert Kern wrote:
> On Sun, Jul 12, 2009 at 14:42, Nicolas Gruel<humufr at yahoo.fr> wrote:
>   
>> Why keeping the numpy comportment (NaN)? If it's only for historical reason and it's mathematicaly better to have 1j, this behaviour should be corrected. It was a limitation of numeric but numpy has been written to extend and to remove the limitation.
>>     
>
> Both behaviors are useful in different situations. It was not a
> limitation of Numeric but rather a specific design decision. Quite
> often, passing a negative number to sqrt() is an error that needs to
> be detected. That's why the standard library has math.sqrt(-1) which
> raises and exception while cmath.sqrt(-1) returns 1j.
>
>   
"it's mathematicaly better to have 1j," It is wrong if it is written in 
the doc that sqrt is a function from R to R.
Maybe what we would need here is a nice one page doc for the newcomers.
The page listing the basic functions in numpy/IDL/matlab is very useful 
when you start with numpy/scipy.
A clear written warning saying that "from scipy import *" is evil could 
also help a lot (iff it contains examples like "sqrt" showing *why* it 
is evil).
Ok, "import *" is not a good practice in python. Not onlyin numpy/scipy 
BUT many users discover python as the same time as they discover 
numpy/scipy.

"it a behaviour is clearly documented with a nice red warning, it is not 
quite a bug ;)"

Xavier




More information about the SciPy-User mailing list