Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6921
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.016 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'def': 0.12; 'wrote:': 0.14; 'brackets': 0.16; 'idea:': 0.16; 'numpy': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'url:effbot': 0.16; 'url:zone': 0.16; 'code': 0.24; 'subject:?': 0.29; 'import': 0.29; 'class': 0.29; 'version': 0.29; 'from:addr:web.de': 0.30; 'ran': 0.30; 'looks': 0.31; 'header:X -Complaints-To:1': 0.32; 'to:addr:python-list': 0.33; 'post': 0.33; 'quite': 0.36; 'tasks': 0.36; 'comparing': 0.37; 'skip:e 20': 0.37; 'received:org': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'should': 0.39; 'skip:m 40': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'square': 0.67; 'url:htm': 0.71; 'subject:this': 0.76; 'fredrik': 0.84; 'ian,': 0.84; 'subject:Why': 0.84; 'subject:much': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Why is this so much faster? |
| Date | Fri, 03 Jun 2011 10:03:27 +0200 |
| Organization | None |
| References | <7c7dee10-8d09-4f4a-9f2e-07564de946d0@glegroupsg2000goo.googlegroups.com> <ef9db7d0-f479-4293-b67f-6e7f10f5721c@glegroupsg2000goo.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p50849488.dip.t-dialin.net |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2420.1307088225.9059.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1307088225 news.xs4all.nl 49179 [::ffff:82.94.164.166]:40400 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:6921 |
Show key headers only | View raw
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