[sage-support] Re: multiply a list by a constant

2008-10-22 Thread Robert Bradshaw
On Oct 21, 2008, at 10:17 PM, pong wrote: Thanks to both Dan and William. However, Dan's result puzzled me. Aren't they suggested that the for loop is faster? Here is what I got: sage: timeit('list(2*vector([random() for j in range(10)]))') 625 loops, best of 3: 332 µs per loop sage:

[sage-support] Re: multiply a list by a constant

2008-10-21 Thread Dan Drake
On Tue, 21 Oct 2008 at 07:50AM -0700, pong wrote: I wrote two list tests: def test1(): for k in range(10^3): v=[2*random() for j in range(10)] else: pass def test2(): for k in range(10^3): v=list(2*vector([random() for j in range(10)]))

[sage-support] Re: multiply a list by a constant

2008-10-21 Thread William Stein
On Tue, Oct 21, 2008 at 4:09 PM, Dan Drake [EMAIL PROTECTED] wrote: On Tue, 21 Oct 2008 at 07:50AM -0700, pong wrote: I wrote two list tests: def test1(): for k in range(10^3): v=[2*random() for j in range(10)] else: pass def test2(): for k in range(10^3):

[sage-support] Re: multiply a list by a constant

2008-10-21 Thread pong
Thanks to both Dan and William. However, Dan's result puzzled me. Aren't they suggested that the for loop is faster? Here is what I got: sage: timeit('list(2*vector([random() for j in range(10)]))') 625 loops, best of 3: 332 µs per loop sage: timeit('[2*random() for j in range(10)]') 125 loops,

[sage-support] Re: multiply a list by a constant

2008-10-20 Thread pong
Thanks Marshall. I have thought about that as well. Since I want to optimize time. I want to see if your method is faster then a for loop. However, I run into something puzzling: vector( [k for k in range(10)]) results in an error. Sage compliant about TypeError: unable to find a common ring

[sage-support] Re: multiply a list by a constant

2008-10-20 Thread William Stein
On Mon, Oct 20, 2008 at 2:06 PM, pong [EMAIL PROTECTED] wrote: Thanks Marshall. I have thought about that as well. Since I want to optimize time. I want to see if your method is faster then a for loop. However, I run into something puzzling: vector( [k for k in range(10)]) results in an

[sage-support] Re: multiply a list by a constant

2008-10-20 Thread pong
Yes, that's what I got. Maybe because I'm only using SAGE 3.1.1 or there is something wrong with the installation. sage: vector([k for k in range(10)]) --- TypeError

[sage-support] Re: multiply a list by a constant

2008-10-20 Thread William Stein
On Mon, Oct 20, 2008 at 2:24 PM, pong [EMAIL PROTECTED] wrote: Yes, that's what I got. Maybe because I'm only using SAGE 3.1.1 or there is something wrong with the installation. I bet that's the case. You should maybe upgrade. We'll be posting binaries soon. William sage: vector([k for

[sage-support] Re: multiply a list by a constant

2008-10-20 Thread Jason Grout
William Stein wrote: On Mon, Oct 20, 2008 at 2:06 PM, pong [EMAIL PROTECTED] wrote: Thanks Marshall. I have thought about that as well. Since I want to optimize time. I want to see if your method is faster then a for loop. However, I run into something puzzling: vector( [k for k in

[sage-support] Re: multiply a list by a constant

2008-10-19 Thread Robert Bradshaw
On Oct 18, 2008, at 10:14 PM, Alex Ghitza wrote: Hmmm. As far as I know you can use _ as a placeholder for a variable, and it's meant for this kind of use (where you don't really want to introduce a new variable name). It's strange that it doesn't work for you. Can you post the

[sage-support] Re: multiply a list by a constant

2008-10-19 Thread Marshall Hampton
Another option is to convert your list to a vector, and then convert it back. This is more awkward for a single operation but if you are doing lots of vector addition and scalar multiplication it can be the way to go. I.e. you can do: sage: a = [3,4] sage: a = list(2*vector(a)) sage: a [6, 8]

[sage-support] Re: multiply a list by a constant

2008-10-18 Thread Alex Ghitza
Hmmm. As far as I know you can use _ as a placeholder for a variable, and it's meant for this kind of use (where you don't really want to introduce a new variable name). It's strange that it doesn't work for you. Can you post the error message that you get? I guess it's not a big deal since