def compute_discount(gamma, maxlen): c = numpy.ones((maxlen,)) * gamma c[0] = 1. c = c.cumprod() C = numpy.triu(numpy.repeat(c[None, :], repeats=maxlen, axis=0)) C /= c[:, None] return C