Geometric Probability Mass Function & Mean
Geometric Probability Mass Function & Mean
Compute the Probability Mass Function (PMF) and Mean of a Geometric distribution.
The Geometric distribution models the number of trials $k$ needed to get the first success in repeated Bernoulli trials with probability of success $p$.
P(X=k)=(1−p)k−1pfor k=1,2,… E[X]=p1Function Arguments
k: list or array- Number of trials integers (k ≥ 1)p: float- Probability of success (0 < p ≤ 1)
Examples
Input: k = [1, 2, 3] p = 0.5
Output: (array([0.5, 0.25, 0.125]), 2.0)
Hint 1
The PMF formula P(X=k)=(1−p)k−1p applies element-wise to k.
Hint 2
Use np.array(k) to convert input to a numpy array for vectorized operations.
Hint 3
The mean is simply 1/p.
Requirements
- Return a tuple
(pmf, mean). pmfshould be a numpy array of the same shape ask.meanshould be a float.- Use
numpy.
Constraints
- n ≥ 2 (need at least 2 samples)
- NumPy only; time limit: 300ms
Log in to take notes on this problem
Accepts: array
Accepts: number
Geometric Probability Mass Function & Mean
Geometric Probability Mass Function & Mean
Compute the Probability Mass Function (PMF) and Mean of a Geometric distribution.
The Geometric distribution models the number of trials $k$ needed to get the first success in repeated Bernoulli trials with probability of success $p$.
P(X=k)=(1−p)k−1pfor k=1,2,… E[X]=p1Function Arguments
k: list or array- Number of trials integers (k ≥ 1)p: float- Probability of success (0 < p ≤ 1)
Examples
Input: k = [1, 2, 3] p = 0.5
Output: (array([0.5, 0.25, 0.125]), 2.0)
Hint 1
The PMF formula P(X=k)=(1−p)k−1p applies element-wise to k.
Hint 2
Use np.array(k) to convert input to a numpy array for vectorized operations.
Hint 3
The mean is simply 1/p.
Requirements
- Return a tuple
(pmf, mean). pmfshould be a numpy array of the same shape ask.meanshould be a float.- Use
numpy.
Constraints
- n ≥ 2 (need at least 2 samples)
- NumPy only; time limit: 300ms
Log in to take notes on this problem
Accepts: array
Accepts: number