Should numpy.sqrt(-1) return 1j rather than nan?

pearu at pearu at
Wed Oct 11 15:06:14 CDT 2006


I have recieved the following note from a user:

In SciPy 0.3.x the ufuncs were overloaded by more "intelligent" versions.
A very attractive feature was that sqrt(-1) would yield 1j as in Matlab.
Then you can program formulas directly (e.g., roots of a 2nd order
polynomial) and the right answer is always achieved. In the Matlab-Python
battle in mathematics education, this feature is important.

Now in SciPy 0.5.x sqrt(-1) yields nan. A lot of code we have, especially
for introductory numerics and physics courses, is now broken.
This has already made my colleagues at the University skeptical to
Python as "this lack of backward compatibility would never happen in Matlab".

Another problem related to Numeric and numpy is that in these courses we
use ScientificPython several places, which applies Numeric and will
continue to do so. You then easily get a mix of numpy and Numeric
in scripts, which may cause problems and at least extra overhead.
Just converting to numpy in your own scripts isn't enough if you call
up libraries using and returning Numeric.

I wonder, what are the reasons that numpy.sqrt(-1) returns nan?
Could sqrt(-1) made to return 1j again? If not, shouldn't
numpy.sqrt(-1) raise a ValueError instead of returning silently nan?


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo

More information about the Numpy-discussion mailing list