Evaluate a Bernoulli distribution at each value in x:
P(X=x)={1−p,p,x=0x=1Its mean and variance are:
μ=p σ2=p(1−p)Here, p is the success probability. Return a dictionary containing pmf as a NumPy array and mean and variance as Python floats.
Input: x = [0, 1, 1], p = 0.3
Output: {"pmf": [0.7, 0.3, 0.3], "mean": 0.3, "variance": 0.21}
Explanation: Failure has probability 0.7, success has probability 0.3, and the distribution moments depend only on p.
Input: x = [0, 1, 0, 1], p = 0.5
Output: {"pmf": [0.5, 0.5, 0.5, 0.5], "mean": 0.5, "variance": 0.25}
Input: x = [1], p = 0.8
Output: {"pmf": [0.8], "mean": 0.8, "variance": 0.16}
Use np.where(x == 1, p, 1.0 - p) for the PMF array.
Compute the variance with p * (1.0 - p).
Sign in to take notes on this problem
Accepts: array
Accepts: number
Evaluate a Bernoulli distribution at each value in x:
P(X=x)={1−p,p,x=0x=1Its mean and variance are:
μ=p σ2=p(1−p)Here, p is the success probability. Return a dictionary containing pmf as a NumPy array and mean and variance as Python floats.
Input: x = [0, 1, 1], p = 0.3
Output: {"pmf": [0.7, 0.3, 0.3], "mean": 0.3, "variance": 0.21}
Explanation: Failure has probability 0.7, success has probability 0.3, and the distribution moments depend only on p.
Input: x = [0, 1, 0, 1], p = 0.5
Output: {"pmf": [0.5, 0.5, 0.5, 0.5], "mean": 0.5, "variance": 0.25}
Input: x = [1], p = 0.8
Output: {"pmf": [0.8], "mean": 0.8, "variance": 0.16}
Use np.where(x == 1, p, 1.0 - p) for the PMF array.
Compute the variance with p * (1.0 - p).
Sign in to take notes on this problem
Accepts: array
Accepts: number