All problems
Laplace PDF
Problem
Laplace (double exponential) probability density with location mu and scale b:
f(x) = exp(-|x - mu| / b) / (2 * b).
Return 0.0 for b <= 0.
Hint
The density is symmetric around mu and decays exponentially.
Test cases
case 1
in: [0,1,0]
expected: 0.5
case 2
in: [0,1,1]
expected: 0.18393972058572117
case 3
in: [1,2,1]
expected: 0.25
case 4
in: [0,-1,0]
expected: 0
Starter codePython
import math
def laplace_pdf(mu, b, x):
# Your code here
pass4 test cases · run your code against them in the editor