Skip to content

demo_package.math

Small collection of numeric utilities for the demo docs.

MovingAverage [source]

Compute a moving average over the most recent values.

Parameters

PARAMETER DESCRIPTION
window

Number of samples used to compute the average. Must be positive.

TYPE: int DEFAULT: 3

update [source]

Add a value to the window and return the current average.

Parameters

PARAMETER DESCRIPTION
value

New data point.

TYPE: float

RETURNS DESCRIPTION
float

The average of the recorded values.

as_dict [source]

Serialize the current state.

RETURNS DESCRIPTION
dict[str, float]

Dictionary with the window size and the number of values seen.

add [source]

Add two numbers.

Parameters

PARAMETER DESCRIPTION
a

First value.

TYPE: float

b

Second value.

TYPE: float

RETURNS DESCRIPTION
float

The sum of both numbers.

Examples

add(1, 2)

scale_values [source]

Scale every value by a factor.

Parameters

PARAMETER DESCRIPTION
values

Iterable of numbers to scale.

TYPE: Iterable[float]

factor

Multiplier applied to each value.

TYPE: float DEFAULT: 1.0

RETURNS DESCRIPTION
list[float]

Scaled values as a list.

RAISES DESCRIPTION
ValueError

If the factor is zero.