Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6921
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Why is this so much faster? |
| Date | 2011-06-03 10:03 +0200 |
| Organization | None |
| References | <7c7dee10-8d09-4f4a-9f2e-07564de946d0@glegroupsg2000goo.googlegroups.com> <ef9db7d0-f479-4293-b67f-6e7f10f5721c@glegroupsg2000goo.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2420.1307088225.9059.python-list@python.org> (permalink) |
Keir Rice wrote:
> Ian, I was basing my code off Fredrik Lundh post on comparing images.
> http://effbot.org/zone/pil-comparing-images.htm
> return math.sqrt(sum([h*i*i for i,h in enumerate(histogram)]) /
> self.Area())
>
> Ran at the same speed as my 'fast' version and without the square brackets
> was slower.
It looks like len(histogram) will always be 256. If so, you can factor out
[i*i for i in range(256)]. For number-crunching tasks considering numpy
might also be a good idea:
# untested
import numpy
deltas = numpy.arange(256, dtype=float)
squares = deltas * deltas
class Whatever:
def RMSBand(self, histogram):
return math.sqrt((squares*histogram).sum()/self.Area())
If it works this should be quite fast.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Why is this so much faster? Keir Rice <keirrice@gmail.com> - 2011-06-02 21:05 -0700 Re: Why is this so much faster? Peter Otten <__peter__@web.de> - 2011-06-03 10:03 +0200
csiph-web