On Fri, Jul 30, 2010 at 4:46 AM, Lawrence D'Oliveiro
<l...@geek-central.gen.new_zealand> wrote:
> Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize
> it (scale all components by the same factor) so its magnitude is 1.
>
> The usual way is something like this:
>
>    L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2])
>    V = (V[0] / L, V[1] / L, V[2] / L)
>
> What I don’t like is having that intermediate variable L leftover after the
> computation. Here’s how to do it in one step:

I suppose you'd be a fan of the proposed "given"/"where" statement
then (but its prognosis isn't great):
http://www.python.org/dev/peps/pep-3150/

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to