Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '(using': 0.05; 'involves': 0.07; 'though.': 0.07; 'precision': 0.09; '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; 'underlying': 0.09; 'pm,': 0.10; 'wrote:': 0.14; 'enigma': 0.16; 'kern': 0.16; 'received:216.62': 0.16; 'received:216.62.213': 0.16; 'received:enthought.com': 0.16; 'subsequent': 0.16; 'question.': 0.16; 'repeated': 0.19; 'thanks,': 0.19; 'header:In-Reply-To:1': 0.21; 'seems': 0.21; 'expect': 0.25; 'up.': 0.26; 'subject:?': 0.29; 'elements': 0.29; 'interpret': 0.29; 'expression': 0.32; 'header:X-Complaints-To:1': 0.32; 'to:addr:python-list': 0.33; 'list': 0.33; 'header:User- Agent:1': 0.35; 'matter,': 0.35; 'using': 0.35; '(with': 0.36; 'floating': 0.37; 'received:org': 0.38; 'but': 0.38; 'though': 0.38; 'size,': 0.38; 'subject:: ': 0.38; 'attempt': 0.39; 'header :Mime-Version:1': 0.39; 'goes': 0.39; 'to:addr:python.org': 0.39; 'really': 0.40; 'world': 0.63; 'our': 0.63; 'believe': 0.66; 'roughly': 0.67; 'square': 0.67; 'lose': 0.84; 'so:': 0.84; 'eco': 0.91; 'gabriel': 0.91; 'subject:Best': 0.91; 'roots': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: Best way to compute length of arbitrary dimension vector? Date: Fri, 03 Jun 2011 18:12:05 -0500 Organization: The Church of Last Thursday References: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> <201106030726.21147.akabaila@pcug.org.au> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: outbound.enthought.com User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307142739 news.xs4all.nl 49178 [::ffff:82.94.164.166]:35307 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6980 On 6/3/11 4:53 PM, Gabriel wrote: > >> The dimension is arbitrary, though, so: >> >> length = reduce(math.hypot, self._coords, 0) >> > > > Thanks, I was going to ask Algis that same question. > > But still, is this solution really faster or better than the one using > list comprehension and the expression 'x*x'? > It seems to me that the above solution (using hypot) involves repeated > square roots (with subsequent squaring). It also means that the floating point numbers stay roughly the same size, so you will lose less precision as the number of elements goes up. I don't expect the number of elements will be large enough to matter, though. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco