Evaluating (not Sampling from) Beta Distribution in Numpy Evaluating (not Sampling from) Beta Distribution in Numpy numpy numpy

Evaluating (not Sampling from) Beta Distribution in Numpy


You are most likely looking for the scipy.stats.beta class. This lets you create a distribution for a particular pair of a, b values:

dist = scipy.stats.beta(a, b)

You can then get the PDF and evaluate at any x:

dist.pdf(x)

x can be any numpy array, not just a scalar. You can evaluate the cumulative distribution in a similar manner:

dist.cdf(x)

You don't even need to create an instance object. This is especially useful if you want to evaluate the function once. In your particular use-case, it would probably be better to create an instance:

scipy.stats.beta.pdf(x, a, b)

The same applies to the CDF. The linked documentation shows lots of other things you can do with the distribution object.

scipy.stats contains many of other common continuous distributions that all follow a similar interface. Any time you have a question related to basic statistics, scipy is the place to start.