TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Geometric Probability Mass Function & Mean

Probability and Statistics
Easy

A Geometric random variable XXX counts the number of trials needed to obtain the first success. Evaluate its PMF at every value in k:

P(X=k)=(1−p)k−1pP(X=k) = (1-p)^{k-1}pP(X=k)=(1−p)k−1p

Its expected number of trials is:

E[X]=1pE[X] = \frac{1}{p}E[X]=p1​

Here, ppp is the success probability and every kkk is a positive integer. Return a dictionary containing pmf as a NumPy array and mean as a Python float.

Loading visualization...

Examples

Input: k = [1, 2, 3], p = 0.2

Output: {"pmf": [0.2, 0.16, 0.128], "mean": 5.0}

Explanation: Each additional failure multiplies the next PMF value by 0.8, while the expected waiting time is 1 divided by 0.2.

Input: k = [1], p = 0.5

Output: {"pmf": [0.5], "mean": 2.0}

Hint 1

Use (1.0 - p) ** (k - 1) * p for the vectorized PMF.

Hint 2

The distribution mean is 1.0 / p.

Requirements

  • Evaluate the Geometric PMF for every value in k
  • Compute the distribution mean
  • Return exactly pmf and mean in a dictionary
  • pmf must be a NumPy array and mean must be a Python float

Constraints

  • k is a nonempty list of positive integers
  • p is greater than 0 and at most 1
  • Use NumPy only
Try Similar Problems
Bernoulli PmfBinomial Pmf CdfPoisson Pmf CdfExpected Value DiscreteSample Var Std

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.
PrevNext

Geometric Probability Mass Function & Mean

Probability and Statistics
Easy

A Geometric random variable XXX counts the number of trials needed to obtain the first success. Evaluate its PMF at every value in k:

P(X=k)=(1−p)k−1pP(X=k) = (1-p)^{k-1}pP(X=k)=(1−p)k−1p

Its expected number of trials is:

E[X]=1pE[X] = \frac{1}{p}E[X]=p1​

Here, ppp is the success probability and every kkk is a positive integer. Return a dictionary containing pmf as a NumPy array and mean as a Python float.

Loading visualization...

Examples

Input: k = [1, 2, 3], p = 0.2

Output: {"pmf": [0.2, 0.16, 0.128], "mean": 5.0}

Explanation: Each additional failure multiplies the next PMF value by 0.8, while the expected waiting time is 1 divided by 0.2.

Input: k = [1], p = 0.5

Output: {"pmf": [0.5], "mean": 2.0}

Hint 1

Use (1.0 - p) ** (k - 1) * p for the vectorized PMF.

Hint 2

The distribution mean is 1.0 / p.

Requirements

  • Evaluate the Geometric PMF for every value in k
  • Compute the distribution mean
  • Return exactly pmf and mean in a dictionary
  • pmf must be a NumPy array and mean must be a Python float

Constraints

  • k is a nonempty list of positive integers
  • p is greater than 0 and at most 1
  • Use NumPy only
Try Similar Problems
Bernoulli PmfBinomial Pmf CdfPoisson Pmf CdfExpected Value DiscreteSample Var Std

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.