Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6960
| From | Alain Ketterlin <alain@dpt-info.u-strasbg.fr> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Standard Deviation One-liner |
| Date | Fri, 03 Jun 2011 20:50:36 +0200 |
| Organization | Universites Paris VI/Paris VII - France |
| Lines | 18 |
| Message-ID | <87oc2erbpf.fsf@dpt-info.u-strasbg.fr> (permalink) |
| References | <isb75r$80h$1@speranza.aioe.org> |
| NNTP-Posting-Host | mob19.u-strasbg.fr |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-Trace | vishnu.jussieu.fr 1307127037 91951 130.79.6.148 (3 Jun 2011 18:50:37 GMT) |
| X-Complaints-To | usenet@vishnu.jussieu.fr |
| NNTP-Posting-Date | Fri, 3 Jun 2011 18:50:37 +0000 (UTC) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) |
| Cancel-Lock | sha1:dDmcXoiIOnVj32cNPr4Mf0MWWXo= |
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!feed.ac-versailles.fr!uvsq.fr!jussieu.fr!not-for-mail |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:6960 |
Show key headers only | View raw
Billy Mays <noway@nohow.com> writes: > I'm trying to shorten a one-liner I have for calculating the standard > deviation of a list of numbers. I have something so far, but I was > wondering if it could be made any shorter (without imports). > a=lambda d:(sum((x-1.*sum(d)/len(d))**2 for x in d)/(1.*(len(d)-1)))**.5 You should make it two half-liners, because this one repeatedly computes sum(d). I would suggest: aux = lambda s1,s2,n: (s2 - s1*s1/n)/(n-1) sv = lambda d: aux(sum(d),sum(x*x for x in d),len(d)) (after some algebra). Completely untested, assumes data come in as floats. You get the idea. -- Alain.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Standard Deviation One-liner Billy Mays <noway@nohow.com> - 2011-06-03 13:55 -0400
Re: Standard Deviation One-liner Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-06-03 20:50 +0200
Re: Standard Deviation One-liner Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-06-03 21:10 +0200
Re: Standard Deviation One-liner Raymond Hettinger <python@rcn.com> - 2011-06-03 13:09 -0700
Re: Standard Deviation One-liner Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-05 17:26 +0000
Re: Standard Deviation One-liner Ethan Furman <ethan@stoneleaf.us> - 2011-06-05 12:17 -0700
csiph-web