Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-062

Gamma PDF Value

Problem

Gamma probability density with shape and rate parameters at x:

f(x) = rate^shape * x^(shape - 1) * e^(-rate * x) / Gamma(shape).

Return 0.0 for nonpositive parameters or x <= 0.

Hint

math.gamma(shape) is the normalizing constant.

Test cases

case 1
in: [1,1,1]
expected: 0.36787944117144233
case 2
in: [2,1,2]
expected: 0.2706705664732254
case 3
in: [3,2,1]
expected: 0.5413411329464508
case 4
in: [1,1,-1]
expected: 0
Starter codePython
import math


def gamma_pdf_value(shape, rate, x):
    # Your code here
    pass

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