From: Charles R H. <cha...@gm...> - 2006-10-13 02:15:56
|
On 10/12/06, Bill Baxter <wb...@gm...> wrote: > > On 10/12/06, Stefan van der Walt <st...@su...> wrote: > > On Thu, Oct 12, 2006 at 08:58:21AM -0500, Greg Willden wrote: > > > On 10/11/06, Bill Baxter <wb...@gm...> 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. |