[Numpy-discussion] New ufuncs

Charles R Harris charlesr.harris at gmail.com
Wed Nov 5 15:00:08 EST 2008


On Wed, Nov 5, 2008 at 12:01 PM, Neal Becker <ndbecker2 at gmail.com> wrote:

> Anne Archibald wrote:
>
> > 2008/11/5 Charles R Harris <charlesr.harris at gmail.com>:
> >> Hi All,
> >>
> >> I'm thinking of adding some new ufuncs. Some possibilities are
> >>
> >> expadd(a,b) = exp(a) + exp(b) -- For numbers stored as logs:
> >
> > Surely this should be log(exp(a)+exp(b))? That would be extremely useful,
> > yes.
> >
> I could probably use this also.  What about log (exp(a)+exp(b)+exp(c)...)?
>

I added the ufunc logsumexp. The extended add should be done with recursive
adds to preserve precision, so:

In [3]: logsumexp.reduce(ones(10))
Out[3]: 3.3025850929940459

In [5]: logsumexp.reduce(eye(3), axis=0)
Out[5]: array([ 1.55144471,  1.55144471,  1.55144471])

It looks like this is a good way to compute L_p norms for large p, i.e.,
exp(logsumexp.reduce(log(abs(x))*p)/p). Adding a logabs ufunc would be
helpful here.

Hmm.... I wonder if the base function should be renamed logaddexp, then
logsumexp would apply to the reduce method. Thoughts?

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20081105/5264b6b6/attachment.html>


More information about the NumPy-Discussion mailing list