[Numpy-discussion] Log Arrays

T J tjhnson@gmail....
Thu May 8 02:26:23 CDT 2008


For precision reasons, I almost always need to work with arrays whose
elements are log values.  My thought was that it would be really neat
to have a 'logarray' class implemented in C or as a subclass of the
standard array class.  Here is a sample of how I'd like to work with
these objects:

>>> x = array([-2,-2,-3], base=2)
>>> y = array([-1,-2,-inf], base=2)
>>> z = x + y
>>> z
array([-0.415037499279, -1.0, -3])
>>> z = x * y
>>> z
array([-3, -4, -inf])
>>> z[:2].sum()

This would do a lot for the code I write....and some of the numerical
stability issues would handled more appropriately.  For example, the
logsum function is frequently handled as:

     log(x + y)  ==  log(x) + log(1 + exp(log(y) - log(x)) )

when log(x) > log(y).   So the goal of the above function is to return
log(x + y)  using only the logarithms of x and y.

Does this sound like a good idea?

More information about the Numpy-discussion mailing list