how to generate increasing sequence of random numbers with given distribution of differences by lambda function

时间:2017-03-22 18:48:27

标签: python loops lambda

It is my second attempt to rid of all the function in my python script and use only lambda (s). First attempt was very successful, many thanks to @vaultah and @ hashcode55: python iterative process inside lambda function, but this one is a bit more complicated. Here the code:

from numpy import *

GammaShape, GammaScale = 4, 2.8

def getsequence(tmin,tmax):
    t=[tmin]
    while t[-1] < tmax: 
        t.append( t[-1]+random.gamma(GammaShape, scale=GammaScale) )
    return t

print getsequence(1,100)

This function returns increasing sequence of time moments with gamma distributed intervals:

[1, 26.428496148321855, 37.98871619324888, 54.30245562952652, 64.30475755683086, 75.76820451443717, 78.62225615406405, 84.16795168540565, 90.64774821744882, 92.51415417744622, 113.42232642308159]

Again, I wondering is it possible to realize this function as lambda without recursion?

0 个答案:

没有答案