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


Groups > comp.lang.python > #6980

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

From Robert Kern <robert.kern@gmail.com>
Subject Re: Best way to compute length of arbitrary dimension vector?
Date 2011-06-03 18:12 -0500
Organization The Church of Last Thursday
References (1 earlier) <mailman.2258.1306749013.9059.python-list@python.org> <a951396d-446b-4ad6-8ad3-d12420e251af@hg8g2000vbb.googlegroups.com> <201106030726.21147.akabaila@pcug.org.au> <mailman.2409.1307056774.9059.python-list@python.org> <c48d6e64-696a-4d4f-9099-c9137bf25fac@16g2000yqy.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.2443.1307142739.9059.python-list@python.org> (permalink)

Show all headers | View raw


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

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