Advertisement
z_californianus

Untitled

Apr 9th, 2020
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. prob_of_sign = .25
  2. weight_probs = {  # this is the solution they prefer
  3.     '3': prob_of_sign,
  4.     '3': prob_of_sign,
  5.     '2': prob_of_sign,
  6.     '5': prob_of_sign
  7. }
  8. expectation = sum(
  9.     [int(x_i)*weight_probs[x_i] for x_i in weight_probs]
  10. )
  11. expectation_of_squares = sum(
  12.     [int(x_i)*int(x_i)*weight_probs[x_i] for x_i in weight_probs]
  13. )
  14. square_of_expectation = expectation**2
  15. variance = expectation_of_squares - square_of_expectation
  16. print('Expected value:', expectation)
  17. print('Variance:', variance)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement