How to make sqrt(-1) be 1j

Charles R Harris charlesr.harris at
Thu Oct 12 21:15:52 CDT 2006

On 10/12/06, Bill Baxter <wbaxter at> wrote:
> On 10/12/06, Stefan van der Walt <stefan at> wrote:
> > On Thu, Oct 12, 2006 at 08:58:21AM -0500, Greg Willden wrote:
> > > On 10/11/06, Bill Baxter <wbaxter at> wrote:
> > I tried to explain the argument at
> >
> >
> >
> The proposed fix for those who want sqrt(-1) to return 1j is:
>    from numpy.lib import scimath as SM
>    SM.sqrt(-1)
> But that creates a new namespace alias, different from numpy.  So I'll
> call numpy.array() to create a new array, but SM.sqrt() when I want a
> square root.
> Am I wrong to want some simple way to change the behavior of
> numpy.sqrt itself?
> Seems like you can get that effect via something like:
>     for n in numpy.lib.scimath.__all__:
>         numpy.__dict__[n] = numpy.lib.scimath.__dict__[n]

I don't like either of those ideas, although the second seems preferable. I
think it better to make an efficient way of calling a sqrt routine that
accepts negative floats and returns complex numbers. The behaviour could be
chosen either by key word or by  specially named routines, or maybe even
some global flag, but I don't think it asking too much for the students to
learn that sqrt(-1) doesn't exist as a real number and that efficient
computation uses real whenever possible because it is a) smaller, and b)
faster. That way we also avoid having software that only works for scimath
but not for numpy.

-------------- next part --------------
An HTML attachment was scrubbed...
-------------- next part --------------
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
-------------- next part --------------
Numpy-discussion mailing list
Numpy-discussion at

More information about the Numpy-discussion mailing list