possibly trivial newbie list/array question

Sylvain Thenault syt at pegasus.logilab.fr
Wed Aug 22 04:15:54 EDT 2001


On Wed, 22 Aug 2001, Sylvain Thenault <syt at pegasus.logilab.fr> wrote:
>On 21 Aug 2001, Michael Williams <michael.williams at st-annes.ox.ac.uk> wrote:
>>I'm an undergraduate doing a relatively simple bit of functional
>>programming, looking at the behaviour of Lorenz attractors. My
>>department recommends (or uses as standard) Pascal. I'd rather avoid
>>this, and Python is something I've been looking into.
>>
>>(Amongst other things!) what I want to do is multiply an array of
>>floating points numbers with a float elementwise, i.e.
>>
>>>>> [1.0, 2.0, 3.0] * 4.0
>>[4.0, 8.0, 12.0]
>>
>
>IMHO, the faster way to do it consists in using builtin map function:
>
>map([1.0, 2.0, 3.0], lambda x: 4.0*x)
>
oops, this is better:
map(lambda x: x*4.0, [1.0, 2.0, 3.0])  

-- 
Sylvain Thenault

LOGILAB




More information about the Python-list mailing list