Statistics Functions

statistics.kde_random()

Construct a random sampler from a kernel density estimate. An optional seed makes repeated runs reproducible within a compatible implementation; sampled values may change across versions. Added in 3.13.

Formal Syntax & Structure

python syntaxpython
statistics.kde_random(data, h, kernel='normal', *, seed=None)

Parameters & Attributes

NameTypeDescription
datasequence of real numbersNonempty observations used for kernel estimation.
hfloatPositive kernel bandwidth.
kernelstrSupported kernel name.
seedint, float, str, bytes, bytearray or NoneOptional pseudorandom seed; None uses default random initialization.

Return Value

Callable[[], float]

Zero-argument sampler function.

Working Example

Example Snippetpython
import statisticsprint(statistics.kde_random([1, 2], 0.5, seed=7)() == statistics.kde_random([1, 2], 0.5, seed=7)())
Python Reference