How to make sqrt(-1) be 1j

Tim Hochberg tim.hochberg at
Fri Oct 13 08:44:25 CDT 2006

Bill Baxter wrote:
> On 10/13/06, Tim Hochberg <tim.hochberg at> wrote:
>> For this sort of thing, I
>> would just make a new module to pull together the function I want and
>> use that instead. It's then easy to explain that this new module bbeconf
>> (Bill Baxter's Excellent Collection Of Numeric Functions) is actually an
>> amalgamation of stuff from multiple sources.
>>     #
>>     from numpy import *
>>     fromnumpy.scimath import sqrt
>>     # possibly some other stuff to correctly handle subpackages...
> That does sound like a good way to do it.
> Then you just tell your users to import 'eduNumpy'  rather than numpy,
> and you're good to go.
> Added that suggestion to
> I'd like to ask one basic Python question related my previous
> suggestion of doing things like "numpy.sqrt = numpy.lib.scimath.sqrt":
> In python does that make it so that any module importing numpy in the
> same program will now see the altered sqrt function?  E.g. in my
> program I do "import A,B".  Module A alters numpy.sqrt.  Does that
> also modify how module B sees numpy.sqrt?
Indeed it does. Module imports are cached in sys.modules, so numpy is 
only imported once. (With some effort, you can usually get your own 
private copy of a module, that you could mess with to your hearts 
content, but I generally wouldn't recommend it).
> If so then that's a very good reason not to do it that way.
> I've heard people using the term "monkey-patch" before.  Is that what that is?
I believe that is what the term refers to although I'm not absolutely 


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