Changing floating point behavior in Python to Numpy style.

Posted by Tristan on Stack Overflow See other posts from Stack Overflow or by Tristan
Published on 2010-06-01T18:07:09Z Indexed on 2010/06/01 18:23 UTC
Read the original article Hit count: 170

Filed under:
|

Is there a way to make Python floating point numbers follow numpy's rules regarding +/- Inf and NaN? For instance, making 1.0/0.0 = Inf.

>>> from numpy import *
>>> ones(1)/0
array([ Inf])
>>> 1.0/0.0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: float division

Numpy's divide function divide(1.0,0.0)=Inf however it is not clear if it can be used similar to from __future__ import division.

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy