Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6899

Re: Why is this so much faster?

References <8bccb0f0-4c1a-4ec8-91b4-4f420d0d8eb9@glegroupsg2000goo.googlegroups.com> <BANLkTik131JNZb4AnpMgB25NHCGS9W4UQQjp-FMtwj38Emyz2g@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-06-02 17:50 -0600
Subject Re: Why is this so much faster?
Newsgroups comp.lang.python
Message-ID <mailman.2410.1307058647.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Jun 2, 2011 at 4:38 PM, Tim Delaney <timothy.c.delaney@gmail.com> wrote:
> First of all, do you have the parameters to the lambda the wrong way around
> in the map() version? zip(histogram, range(255)) will return (histogram
> value, index), but enumerate(histogram) will return (index, histogram
> value). But the parameters haven't been swapped, resulting in the histogram
> value being squared in the map version, but the index being squared in the
> manual summing version. Depending on the values, this could result in a
> large performance increase in the second version (if the total value exceeds
> the maximum size of your platform's "long" type).

In addition to what Tim said, I question whether you should even be
multiplying by the index at all.  The usual definition of "root mean
square" is this:

math.sqrt(sum(x * x for x in values) / len(values))

I don't know the problem that you're trying to solve, though, so maybe
I am just being confused by your terminology.

Cheers,
Ian

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Why is this so much faster? Keir Rice <keirrice@gmail.com> - 2011-06-02 15:07 -0700
  Re: Why is this so much faster? Terry Reedy <tjreedy@udel.edu> - 2011-06-02 19:04 -0400
  Re: Why is this so much faster? Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-02 17:50 -0600

csiph-web