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

Robert Kern robert.kern@gmail....
Sun Jul 12 01:01:25 CDT 2009

On Sat, Jul 11, 2009 at 16:56, Xavier Gnata<xavier.gnata@gmail.com> wrote:
> 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.

As with most such things, the answer is "history". Old Numeric had
only the NaN behavior. scipy added functions with the 1j behavior.
When numpy was formed, it kept the NaN behavior for the functions in
the main numpy namespace and moved the 1j implementations from scipy
into numpy.lib.scimath. scipy kept the 1j behaviors for the functions
it exposes.

Personally, I suggest simply forgetting that the scipy namespace
aliases the numpy functions and only use the subpackages in scipy. Use
the functions from numpy or numpy.lib.scimath directly, as needed.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the SciPy-user mailing list