Should numpy.sqrt(-1) return 1j rather than nan?
Andrew Jaffe
a.h.jaffe at gmail.com
Thu Oct 12 11:35:19 EDT 2006
Tim Hochberg wrote:
> Travis Oliphant wrote:
>> Tim Hochberg wrote:
>>
>>
>>> With python 2.5 out now, perhaps it's time to come up with a with
>>> statement context manager. Something like:
>>>
>>> a = numpy.arange(10)
>>> a/a # ignores divide by zero
>>> with errstate(divide='raise'):
>>> a/a # raise exception on divide by zer
>>> # Would ignore divide by zero again if we got here.
>>>
>>> -tim
>>>
>> This looks great. I think most people aren't aware of the with
>> statement and what it can do (I'm only aware because of your posts, for
>> example).
>>
>> So, what needs to be added to your example in order to just add it to
>> numpy?
>>
> As far as I know, just testing and documentation -- however testing was
> so minimal that I may find some other stuff. I'll try to clean it up
> tomorrow so that I'm a little more confident that it works correctly and
> I'll send another note out then.
For this particular application, why not a context manager which just
substitutes in the appropriately-optimized version of sqrt? That is,
don't change the error state, but actually change the value of the
object pointed at by the name sqrt?
Andrew
-------------------------------------------------------------------------
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
More information about the NumPy-Discussion
mailing list