Compute the expected value of a discrete random variable given its values and probabilities.
Expected Value:
E[X]=i=0∑N−1xipiwhere xi are the values and pi are their corresponding probabilities with ∑pi=1.
x: array-like, shape (N,) - possible valuesp: array-like, shape (N,) - corresponding probabilitiesInput: x = [1, 2, 3], p = [0.2, 0.5, 0.3]
Output: E[X] = 2.1
Input: x = [1, 2, 3, 4], p = [0.25, 0.25, 0.25, 0.25]
Output: E[X] = 2.5
First validate that probabilities sum to 1 using np.allclose().
Compute element-wise product of x and p, then sum using np.sum().
ValueError if probabilities don't sum to 1 (within tolerance 10−6) - any error message is acceptedSign in to take notes on this problem
Accepts: array
Accepts: array
Compute the expected value of a discrete random variable given its values and probabilities.
Expected Value:
E[X]=i=0∑N−1xipiwhere xi are the values and pi are their corresponding probabilities with ∑pi=1.
x: array-like, shape (N,) - possible valuesp: array-like, shape (N,) - corresponding probabilitiesInput: x = [1, 2, 3], p = [0.2, 0.5, 0.3]
Output: E[X] = 2.1
Input: x = [1, 2, 3, 4], p = [0.25, 0.25, 0.25, 0.25]
Output: E[X] = 2.5
First validate that probabilities sum to 1 using np.allclose().
Compute element-wise product of x and p, then sum using np.sum().
ValueError if probabilities don't sum to 1 (within tolerance 10−6) - any error message is acceptedSign in to take notes on this problem
Accepts: array
Accepts: array