You will write functions for the mean and the variance of a distribution stored as a dictionary, and for the distribution of . The checker uses the heads in three tosses of a coin.
The idea. A distribution is a dictionary that maps each value to its probability. The mean is . The variance is . The variable takes the value with the same probability as .
Your tasks.
mean(pmf). Add x * p for every value.variance(pmf). Find the mean of the squares and subtract the square of the mean.shift_scale(pmf, a, b). Return a new dictionary with the keys a * x + b.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…