Best way to compute length of arbitrary dimension vector?

Ian Kelly ian.g.kelly at gmail.com
Thu Jun 2 19:19:02 EDT 2011


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



More information about the Python-list mailing list