Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.065 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'pm,': 0.10; 'wrote:': 0.14; 'math': 0.16; 'cheers,': 0.19; 'header:In-Reply-To:1': 0.21; 'thu,': 0.22; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'received:209.85.161': 0.26; 'message- id:@mail.gmail.com': 0.28; 'subject:?': 0.29; 'import': 0.29; 'to:addr:python-list': 0.33; 'received:google.com': 0.37; 'received:209.85': 0.37; 'subject:: ': 0.38; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'so:': 0.84; 'subject:Best': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=ac6Cc94X8VcvIfAUhoM0GBKQDSYImlk2HVLCEtW9mB8=; b=OiorXcCJf2AXUZsRout5LF2GDMDSnR7Pauy5mxlpQU96VdkBYMDE2GU/EE1SyPovHi bA0MK3l/qo5GT+4NeHVX2infexv9u0y8udU/hH0cWcyNm/rIqSpz4HgzVT9Dw/2YwPwE mCq6egaUoT5zX686M+oe8k8p2LeSEle1Dm8yk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=B2tAKGvZuosJOxdZ9/2grPV+25zRtk4CqLIQHaUAuqyO4zorH6J68y+aqHk7FdCnN8 /tvU7KuMUJDHRaDMUjUKw4uey4D7QrgIV0EwK9rG2FQCzWztVWnD4uoDSp4wPpCGnkAg 50SUogbAeF2gLLntrKatNIKvzPGdm4nYXIIb0= MIME-Version: 1.0 In-Reply-To: <201106030726.21147.akabaila@pcug.org.au> References: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> <201106030726.21147.akabaila@pcug.org.au> From: Ian Kelly Date: Thu, 2 Jun 2011 17:19:02 -0600 Subject: Re: Best way to compute length of arbitrary dimension vector? To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 13 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307056774 news.xs4all.nl 49044 [::ffff:82.94.164.166]:59323 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6896 On Thu, Jun 2, 2011 at 3:26 PM, Algis Kabaila wrote: > import math > > length = math.hypot(z, math.hypot(x, y)) > > One line and fast. The dimension is arbitrary, though, so: length = reduce(math.hypot, self._coords, 0) Cheers, Ian