On 2010-01-11 14:31 PM, CELEN Erman wrote:
(I also noticed that this behavior is same under standard NumPy 1.4
with standard Python 2.6 on Windows. If you call numpy.log10(0.0) you
will get an "-inf" and no exceptions will be raised. Which is not the
case with Python's standard math.log10(0.0) which will raise a
ValueError)

Correct. This is numpy's intended behavior. See numpy.seterr() to enable
exceptions if you want them.

Numpy.seterr() doesn't seem to be working in case of log10(0.0) (output with 
all standard: Python2.6 with NumPy1.4 on Windows-32bit is below)

   Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] 
on win32
   Type "help", "copyright", "credits" or "license" for more information.
   >>>  import numpy
   >>>  numpy.seterr()
   {'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore', 'under': 
'ignore'}
   >>>  numpy.int16(32000) * numpy.int16(3)
   30464
   >>>  numpy.log10(0.0)
   -inf
   >>>  numpy.seterr(all='raise')
   {'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore', 'under': 
'ignore'}
   >>>  numpy.int16(32000) * numpy.int16(3)
   Traceback (most recent call last):
     File "<stdin>", line 1, in<module>
   FloatingPointError: overflow encountered in short_scalars
   >>>  numpy.log10(0.0)
   -inf
   >>>  numpy.log10(-1.0)
   nan
   >>>  numpy.seterr()
   {'over': 'raise', 'divide': 'raise', 'invalid': 'raise', 'under': 'raise'}
   >>>

That might be an issue with how numpy is detecting the floating point exception on Windows. Please report it. It works fine on OS X:

In [1]: np.seterr(all='raise')
Out[1]: {'divide': 'print', 'invalid': 'print', 'over': 'print', 'under': 
'ignore'}

In [2]: np.log10(0.0)
---------------------------------------------------------------------------
FloatingPointError                        Traceback (most recent call last)

/Users/rkern/<ipython console> in <module>()

FloatingPointError: divide by zero encountered in log10

In [3]: np.log10(-1.0)
---------------------------------------------------------------------------
FloatingPointError                        Traceback (most recent call last)

/Users/rkern/<ipython console> in <module>()

FloatingPointError: invalid value encountered in log10

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to