Inhomogeneous Poisson spike train generation

# generate spike train
def gen_spikes(r,dt):
    i = 0
    s = 0
    spks = []
    while True:
        s += -np.log(1-np.random.uniform())
        while s>r[i]*dt:
            s -= r[i]*dt
            i += 1
            if i>=len(r): break
        else:
            spks.append(i*dt+s/r[i])
            continue
        break
    return spks