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
--
http://mail.python.org/mailman/listinfo/python-list