from functools import reduce
def dirichlet_pdf(x, alpha):
    return math.gamma(sum(alpha)) / reduce(operator.mul, [math.gamma(a) for
        a in alpha]) * reduce(operator.mul, [(x[i] ** (alpha[i] - 1.0)) for
        i in range(len(alpha))])
Calculating pdf of Dirichlet distribution in python