[Python-Dev] Fwd: summing a bunch of numbers (or "whatevers")

Prabhu Ramachandran prabhu@aero.iitm.ernet.in
Sun, 20 Apr 2003 13:21:13 +0530

>>>>> "AM" == Alex Martelli <aleax@aleax.it> writes:

    >> argue that sum is necessary, what about product (which again
    >> Numeric provides along with a host of other useful functions)?

    AM> In the context of Numeric use, it's quite appropriate to have
    AM> sum, prod, and the other ufuncs' reduce AND accumulate
    AM> methods.  In everyday programming in other fields, the demand
    AM> for the functionality given by sum is FAR higher than that
    AM> given by prod.  For example, googling on c.l.py shows 165
    AM> posts mentioning "reduce(operator.add" versus 39 mentioning
    AM> "reduce(operator.mul".  This reflects the need of typical
    AM> computations -- indeed, even the English language shows
    AM> indications about the prevalence of summing as a bulk
    AM> operation.

I agree that sum will be used far more than product.  I can't remember
when I needed to use product myself!  Anyway here are the arguments
I've seen so far.


  1. One obvious, fairly efficient, and easy way to sum sequences.

  2. Google and experience suggest sum is used more often than
  product and other functions.

  3. Easy on newbies?

  4. Will hopefully prevent the N+1'th thread on how to sum lists on

  1. __builtins__ is already fat.  Will one more function make that
  much difference?

  2. Will future requests be made for product and friends?

  3. Why not simply speed up reduce/operator.add and train more people
  to use that?