Normalizing A Vector
Lawrence D'Oliveiro
ldo at geek-central.gen.new_zealand
Sat Jul 31 06:15:57 EDT 2010
In message <877hkdhyl5.fsf at dpt-info.u-strasbg.fr>, Alain Ketterlin wrote:
> Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> writes:
>
>> What I don’t like is having that intermediate variable L leftover after
>> the computation.
>
> Well, it also guarantees that the square root is computed once.
OK, this version should solve that problem, without requiring any new
language features:
V = tuple \
(
x
/
l
for x in V
for l in
(math.sqrt(reduce(lambda a, b : a + b, (y * y for y in V), 0)),)
)
More information about the Python-list
mailing list