How to make sqrt(-1) be 1j

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


On 10/12/06, Bill Baxter <wbaxter at gmail.com> wrote:
>
> On 10/12/06, Stefan van der Walt <stefan at sun.ac.za> wrote:
> > On Thu, Oct 12, 2006 at 08:58:21AM -0500, Greg Willden wrote:
> > > On 10/11/06, Bill Baxter <wbaxter at gmail.com> wrote:
> > I tried to explain the argument at
> >
> > http://www.scipy.org/NegativeSquareRoot
> >
>
> 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.

Chuck.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20061012/c03639d1/attachment.html 
-------------- 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
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
-------------- next part --------------
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


More information about the Numpy-discussion mailing list