[Numpy-discussion] New ufuncs
Charles R Harris
Wed Nov 5 14:00:08 CST 2008
On Wed, Nov 5, 2008 at 12:01 PM, Neal Becker <firstname.lastname@example.org> wrote:
> Anne Archibald wrote:
> > 2008/11/5 Charles R Harris <email@example.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 : logsumexp.reduce(ones(10))
In : logsumexp.reduce(eye(3), axis=0)
Out: 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
Hmm.... I wonder if the base function should be renamed logaddexp, then
logsumexp would apply to the reduce method. Thoughts?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion