Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6896

Re: Best way to compute length of arbitrary dimension vector?

References <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> <mailman.2258.1306749013.9059.python-list@python.org> <a951396d-446b-4ad6-8ad3-d12420e251af@hg8g2000vbb.googlegroups.com> <201106030726.21147.akabaila@pcug.org.au>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-06-02 17:19 -0600
Subject Re: Best way to compute length of arbitrary dimension vector?
Newsgroups comp.lang.python
Message-ID <mailman.2409.1307056774.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Jun 2, 2011 at 3:26 PM, Algis Kabaila <akabaila@pcug.org.au> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Best way to compute length of arbitrary dimension vector? Gabriel <snoopy.67.z@googlemail.com> - 2011-05-30 02:11 -0700
  Re: Best way to compute length of arbitrary dimension vector? Chris Rebert <clp2@rebertia.com> - 2011-05-30 02:24 -0700
  Re: Best way to compute length of arbitrary dimension vector? Peter Otten <__peter__@web.de> - 2011-05-30 11:46 +0200
    Re: Best way to compute length of arbitrary dimension vector? Gabriel <snoopy.67.z@googlemail.com> - 2011-05-30 06:38 -0700
      Re: Best way to compute length of arbitrary dimension vector? Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-02 17:19 -0600
        Re: Best way to compute length of arbitrary dimension vector? Gabriel <snoopy.67.z@googlemail.com> - 2011-06-03 14:53 -0700
          Re: Best way to compute length of arbitrary dimension vector? Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-03 16:17 -0600
          Re: Best way to compute length of arbitrary dimension vector? Robert Kern <robert.kern@gmail.com> - 2011-06-03 18:12 -0500
  Re: Best way to compute length of arbitrary dimension vector? "Gabriel Genellina" <gagsl-py2@yahoo.com.ar> - 2011-05-30 16:01 -0300
    Re: Best way to compute length of arbitrary dimension vector? Gabriel <snoopy.67.z@googlemail.com> - 2011-06-01 12:35 -0700

csiph-web