Problems
Loading...
1 / 1

Geometric Probability Mass Function & Mean

Probability and Statistics
Easy

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)=(1p)k1pfor k=1,2,P(X=k) = (1-p)^{k-1} p \quad \text{for } k=1, 2, \dots E[X]=1pE[X] = \frac{1}{p}

Function Arguments

  • k: list or array - Number of trials integers (k ≥ 1)
  • p: float - Probability of success (0 < p ≤ 1)
Loading visualization...

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)=(1p)k1pP(X=k) = (1-p)^{k-1}p applies element-wise to kk.

Hint 2

Use np.array(k) to convert input to a numpy array for vectorized operations.

Hint 3

The mean is simply 1/p1/p.

Requirements

  • Return a tuple (pmf, mean).
  • pmf should be a numpy array of the same shape as k.
  • mean should be a float.
  • Use numpy.

Constraints

  • n ≥ 2 (need at least 2 samples)
  • NumPy only; time limit: 300ms
Try Similar Problems