Is there a list comprehension for this?
robert.kern at gmail.com
Tue Nov 21 23:41:03 CET 2006
> dw = [ 1, -1.1, +1.2 ]
> Suppose I want to create a list 'w' that is defined as
> w = dw,
> w = w + dw,
> w = w + dw
> Is there a list comprehension or map expression to do it in one or 2
One way is to use numpy (numpy.scipy.org):
In : from numpy import cumsum
In : dw = [1, -1.1, +1.2]
In : cumsum(dw)
Out: array([ 1. , -0.1, 1.1])
If you're doing a lot of numerical computing, you'll probably want a number of
other things that numpy provides.
"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
More information about the Python-list