Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-058

Rayleigh PDF

Problem

Rayleigh probability density function with scale sigma:

f(x) = (x / sigma^2) * exp(-x^2 / (2 * sigma^2)) for x >= 0, else 0.

Return 0.0 for sigma <= 0.

Hint

The density peaks at x = sigma.

Test cases

case 1
in: [1,0]
expected: 0
case 2
in: [1,1]
expected: 0.6065306597126334
case 3
in: [2,2]
expected: 0.3032653298563167
case 4
in: [1,-1]
expected: 0
Starter codePython
import math


def rayleigh_pdf(sigma, x):
    # Your code here
    pass

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