def betaNLL(param, *args):
    """
    Negative log likelihood function for beta
    <param>: list for parameters to be fitted.
    <args>: 1-element array containing the sample data.
    Return <nll>: negative log-likelihood to be minimized.
    """
a, b = param
data = args[0]
pdf = beta.pdf(data, a, b, loc=0, scale=1)
lg = np.log(pdf)
mask = np.isfinite(lg)
nll = -lg[mask].sum()
return nll
How to properly fit a beta distribution in python?