Coding the uniform probability density function

50 Views Asked by At

In the chapter about the probability of Data Science from Scratch the author says:

the density function for the uniform distribution is just:

def uniform_pdf(x):
    return 1 if x>= 0 and x <1 else 0

Whereas on Wikipedia, one can read that

The probability density function of the continuous uniform distribution is:

$$f(x)={\begin{cases}{\frac {1}{b-a}}&\mathrm {for} \ a\leq x\leq b,\\[8pt]0&\mathrm {for} \ x<a\ \mathrm {or} \ x>b\end{cases}}$$

So shouldn't it be:

def uniform_pdf(x, a, b):
    return 1/(b - a) if x>= 0 and x <1 else 0

Here is the full excerpt:

enter image description here