Implement the Bernoulli Probability Mass Function (PMF) and compute the distribution's mean and variance for given inputs.
Bernoulli Distribution:
Probability Mass Function:
P(X=1)=p,P(X=0)=1−pMean and Variance:
μ=p,σ2=p(1−p)x: scalar, list, or array - Values of 0s and 1sp: float - Success probability (0 ≤ p ≤ 1)Input: x=[0, 1, 1], p=0.3
Output: pmf=[0.7, 0.3, 0.3], mean=0.3, var=0.21
Input: x=[1], p=0.8
Output: pmf=[0.8], mean=0.8, var=0.16
Input: x=[0, 1, 0, 1], p=0.5
Output: pmf=[0.5, 0.5, 0.5, 0.5], mean=0.5, var=0.25
Use np.where() to assign probabilities.
Mean is simply p, variance is p * (1 - p).
Convert to float using float() for mean and variance return values.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Implement the Bernoulli Probability Mass Function (PMF) and compute the distribution's mean and variance for given inputs.
Bernoulli Distribution:
Probability Mass Function:
P(X=1)=p,P(X=0)=1−pMean and Variance:
μ=p,σ2=p(1−p)x: scalar, list, or array - Values of 0s and 1sp: float - Success probability (0 ≤ p ≤ 1)Input: x=[0, 1, 1], p=0.3
Output: pmf=[0.7, 0.3, 0.3], mean=0.3, var=0.21
Input: x=[1], p=0.8
Output: pmf=[0.8], mean=0.8, var=0.16
Input: x=[0, 1, 0, 1], p=0.5
Output: pmf=[0.5, 0.5, 0.5, 0.5], mean=0.5, var=0.25
Use np.where() to assign probabilities.
Mean is simply p, variance is p * (1 - p).
Convert to float using float() for mean and variance return values.
Sign in to take notes on this problem
Accepts: array
Accepts: number