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

2011-06-03 Thread Gabriel
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

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

2011-06-03 Thread Ian Kelly
On Fri, Jun 3, 2011 at 3:53 PM, Gabriel snoopy.6...@googlemail.com wrote: But still, is this solution really faster or better than the one using list comprehension and the expression 'x*x'? No, not really. c:\python32\python -m timeit -s coords = list(range(100)) -s from math import hypot -s

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

2011-06-03 Thread Robert Kern
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'?

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

2011-06-02 Thread Algis Kabaila
On Monday 30 May 2011 23:38:53 Gabriel wrote: Thanks a lot to both of you, Chris Peter! (I knew the solution would be simple ... ;-) ) import math length = math.hypot(z, math.hypot(x, y)) One line and fast. OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf --

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

2011-06-02 Thread Ian Kelly
On Thu, Jun 2, 2011 at 3:26 PM, Algis Kabaila akaba...@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 --

Best way to compute length of arbitrary dimension vector?

2011-05-30 Thread Gabriel
Well, the subject says it almost all: I'd like to write a small Vector class for arbitrary-dimensional vectors. I am wondering what would be the most efficient and/or most elegant way to compute the length of such a Vector? Right now, I've got def length(self):

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

2011-05-30 Thread Chris Rebert
On Mon, May 30, 2011 at 2:11 AM, Gabriel snoopy.6...@googlemail.com wrote: Well, the subject says it almost all: I'd like to write a small Vector class for arbitrary-dimensional vectors. I am wondering what would be the most efficient and/or most elegant way to compute the length of such a

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

2011-05-30 Thread Peter Otten
Gabriel wrote: Well, the subject says it almost all: I'd like to write a small Vector class for arbitrary-dimensional vectors. I am wondering what would be the most efficient and/or most elegant way to compute the length of such a Vector? Right now, I've got def length(self):

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

2011-05-30 Thread Gabriel
Thanks a lot to both of you, Chris Peter! (I knew the solution would be simple ... ;-) ) -- http://mail.python.org/mailman/listinfo/python-list

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

2011-05-30 Thread Gabriel Genellina
En Mon, 30 May 2011 06:46:01 -0300, Peter Otten __pete...@web.de escribió: Gabriel wrote: Well, the subject says it almost all: I'd like to write a small Vector class for arbitrary-dimensional vectors. class Vector(object): ... def __init__(self, *coords): ...