Re: multiply each element of a list by a number

2008-12-29 Thread skip
Colin> That's interesting but that's not the Colin> way timeit is documented for Python 2.5: Colin> timeit( [number=100]) That's how it works when invoked as a main program using -m. Colin> In spite of the fact that your own data doesn't support the Colin> assertion?

Re: multiply each element of a list by a number

2008-12-29 Thread Colin J. Williams
s...@pobox.com wrote: "Colin" == Colin J Williams writes: Colin> s...@pobox.com wrote: >> For extremely short lists, but not for much else: >> >> % for n in 1 10 100 1000 1 10 ; do >> > echo "len:" $n >> > echo -n "numpy: " >> > python -m timeit -s

Re: multiply each element of a list by a number

2008-12-29 Thread skip
> "Colin" == Colin J Williams writes: Colin> s...@pobox.com wrote: >> For extremely short lists, but not for much else: >> >> % for n in 1 10 100 1000 1 10 ; do >> > echo "len:" $n >> > echo -n "numpy: " >> > python -m timeit -s 'import numpy ; a =

Re: multiply each element of a list by a number

2008-12-28 Thread Colin J. Williams
s...@pobox.com wrote: Colin> ... perhaps faster than numpy: ... For extremely short lists, but not for much else: % for n in 1 10 100 1000 1 10 ; do > echo "len:" $n > echo -n "numpy: " > python -m timeit -s 'import numpy ; a = numpy.array(range('$n'))' 'a*

Re: multiply each element of a list by a number

2008-12-27 Thread skip
Colin> ... perhaps faster than numpy: ... For extremely short lists, but not for much else: % for n in 1 10 100 1000 1 10 ; do > echo "len:" $n > echo -n "numpy: " > python -m timeit -s 'import numpy ; a = numpy.array(range('$n'))' 'a*3' > echo -n "lis

Re: multiply each element of a list by a number

2008-12-27 Thread Colin J. Williams
Méta-MCI (MVP) wrote: Hi! map(multby3, (1, 2, 3, )) with lambda: map(lambda x: x*3, [1,2,3]) @-salutations More lines but perhaps faster than numpy: PythonWin 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32. Portions Copyright 1994-2008 Mark Hammo

Re: multiply each element of a list by a number

2008-12-27 Thread MVP
Hi! map(multby3, (1, 2, 3, )) ...with lambda: map(lambda x: x*3, [1,2,3]) @-salutations -- Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list

Re: multiply each element of a list by a number

2008-12-26 Thread Brian Blais
On Dec 26, 2008, at 19:05 , robert.t.ly...@seagate.com wrote: but this seems overkill to me. Can you tell I am coming to Python from Matlab? if you're coming from matlab, then you should think of python lists more like cell arrays than matrices: you can have lists of arbitrary data type

Re: multiply each element of a list by a number

2008-12-26 Thread Martin
you might also want to look into the map(elem), and filter(elem) builtins >>> def multby3(elem): ... return elem * 3 ... >>> map(multby3, (1, 2, 3, )) [3, 6, 9] >>> help(map) >>> def even(elem): ... return not elem % 2 ... >>> filter(even, (1, 2, 3, )) (2,) >>> help(filter) KeyboardInterr

Re: multiply each element of a list by a number

2008-12-26 Thread Scott David Daniels
Tim Chase wrote: What does *not* work is 3 * [0,1,2] As you know, this gives [0,1,2,0,1,2,0,1,2] What I am hoping for is [0,3,6] I see that I can use numpy.multiply(3,range(3)) The common way to do this is just a1 = [0,1,2] a2 = [x * 3 for x in a1] ... But a

Re: multiply each element of a list by a number

2008-12-26 Thread Tim Chase
What does *not* work is 3 * [0,1,2] As you know, this gives [0,1,2,0,1,2,0,1,2] What I am hoping for is [0,3,6] I see that I can use numpy.multiply(3,range(3)) but this seems overkill to me. Can you tell I am coming to Python from Matlab? The common way to do

Re: multiply each element of a list by a number

2008-12-26 Thread Benjamin Kaplan
On Fri, Dec 26, 2008 at 7:05 PM, wrote: > > What does *not* work is > 3 * [0,1,2] > As you know, this gives > [0,1,2,0,1,2,0,1,2] > What I am hoping for is > [0,3,6] > I see that I can use > numpy.multiply(3,range(3)) > but this seems overkill to me. Can you tell