[Numpy-discussion] Simple multi-arg wrapper for dot()

Bill Baxter wbaxter@gmail....
Sat Mar 24 13:52:27 CDT 2007

On 3/24/07, Steven H. Rogers <steve@shrogers.com> wrote:
> Anne Archibald wrote:
> >
> > P.S. reduce isn't even a numpy thing, it's one of python's
> > much-neglected lispy functions.
> >
> It looks like reduce(), map(), and filter() are going away for Python
> 3.0 since GvR believes that they are redundant and list comprehensions
> and generator expressions are more readable alternatives.  lambda was on
> the block as well, but will be retained.

Are you sure reduce is on the chopping block?  The PEP for generator
expressions doesn't say anything about reduce becoming redundant.
They give the example of
  reduce(lambda s, a: s + a.myattr, data, 0)
  sum(a[3] for a in data)

but that does nothing to address how functions like sum themselves
should be written. For a general binary operator, the equivalent of
"sum" can be conveniently expressed as a reduce operation.

As far as I can tell Python has no "prod" function.  So if one just
changes the example to
  reduce(lambda s, a: s * a.myattr, data, 1)
How does one write that in a simplified way using generator
expressions without calling on reduce?


More information about the Numpy-discussion mailing list