Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-039

Convolution of Two PMFs

Problem

Convolution of two discrete probability mass functions.

If out = convolve(pmf_a, pmf_b) then out[k] = sum over i of pmf_a[i] * pmf_b[k - i], the distribution of the sum of two independent variables. Return an empty list if either input is empty.

Hint

Pair every outcome of the first variable with every outcome of the second.

Test cases

case 1
in: [[0.5,0.5],[0.5,0.5]]
expected: [0.25,0.5,0.25]
case 2
in: [[1],[0.3,0.7]]
expected: [0.3,0.7]
case 3
in: [[0.2,0.8],[1]]
expected: [0.2,0.8]
case 4
in: [[0.3,0.7],[0.4,0.6]]
expected: [0.12,0.45999999999999996,0.42]
case 5
in: [[0.5,0.5],[0.5,0.5,0]]
expected: [0.25,0.5,0.25,0]
Starter codePython
def convolution_pmfs(pmf_a, pmf_b):
    # Your code here
    pass

5 test cases · run your code against them in the editor