Consider random variables and . Assume that takes values 1,…, with probabilities 1,…, and takes values 1,…, with probabilities 1,…, . Assume that and are independent. Implement function joint_pmf(xvalues, xprobs, yvalues, yprobs) that takes an array of values 1,…, as xvalues, an array of probabilities 1,…, as xprobs and the same with yvalues and yprobs. The function should return a dictionary which keys are tuples (x, y) where x is some value and y is and corresponding values are values of joint probability mass function ,(,)
def joint_pmf(xvalues, xprobs, yvalues, yprobs):
# your code
testdata = [([1], [1], [2, 3], [0.2, 0.8]),
([1, 2], [0.5, 0.5], [3, 4, 5], [0.3, 0.3, 0.4])]
answers = [{(1, 2): 0.2, (1, 3): 0.8},
{(1, 3): 0.15,
(1, 4): 0.15,
(1, 5): 0.2,
(2, 3): 0.15,
(2, 4): 0.15,
(2, 5): 0.2}]
for data, answer in zip(testdata, answers):
assert joint_pmf(*data) == answer
I can't understand the task before going to the solution. For example, there are only two probabilities in testdata for 4 x values ([1], [1], [2, 3], [0.2, 0.8])? Why is there no such value in answers like x=1 and y=1? {(1,1): ...}? Could you please give an explanation or your solution?