All problems
Variance of Discrete RV
Problem
Compute the variance of a discrete random variable:
Var(X) = sum((v_i - E[X])^2 * p_i)
where E[X] = sum(v_i * p_i).
Hint
E[X^2] - (E[X])^2 also works, but the direct definition is cleaner here.
Test cases
case 1
in: [[1,2,3,4,5,6],[0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666]]
expected: 2.9166666666666665
case 2
in: [[0,1],[0.5,0.5]]
expected: 0.25
case 3
in: [[5,5,5],[0.3333333333333333,0.3333333333333333,0.3333333333333333]]
expected: 0
Starter codePython
def variance_discrete_rv(values, probabilities):
# Your code here
pass3 test cases · run your code against them in the editor