Kahan#

The kahan package provides efficient implementations of Kahan’s algorithms for numerical summation and other basic statistical calculations. These algorithms are designed to reduce the loss of precision that can occur when adding a large number of floating-point values.

For more information on Kahan’s algorithms and their implementation in the kahan package, please see the package documentation.

References:

Kahan, W. (1965). Pracniques: Further remarks on reducing truncation errors. Communications of the ACM, 8(1), 40-41.

Summary#

kahan.cummean(a)

Cumulative mean.

kahan.cumsum(a)

Cumulative sum.

kahan.cumvariance(a)

Cumulative mean and variance.

kahan.mean(a)

Return the mean of iterable `a'.

kahan.sum(a)

Return the sum of iterable `a'.

Functions#

kahan.cummean(a)#

Cumulative mean.

Return an iterator over yielding cumulative means of an input sequence

Parameters#

aiterable

Input sequence

Returns#

iterator

An iterator that yields cumulative means.

Examples#

>>> list(cummean([1, 2, 3, 4]))
[1.0, 1.5, 2.0, 2.5]
kahan.cumsum(a)#

Cumulative sum.

Return an iterator over yielding cumulative sums of an input sequence

Parameters#

aiterable

Input sequence

Returns#

iterator

An iterator that yields cumulative sums.

Examples#

>>> list(cumsum([1, 2, 3, 4]))
[1.0, 3.0, 6.0, 10.0]
kahan.cumvariance(a)#

Cumulative mean and variance.

Return an iterator over yielding pairs of cumulative mean and cumulative variance of an input sequence

Parameters#

aiterable

Input sequence

Returns#

iterator

An iterator that yields pairs of cumulative mean and cumulative variance.

Examples#

>>> list(cumvariance([1, 7, 4]))
[(1.0, 0.0), (4.0, 9.0), (4.0, 6.0)]
kahan.mean(a)#

Return the mean of iterable `a’.

Return the cumulative mean of an input sequence

Parameters#

aiterable

Input sequence

Returns#

float

The cumulative mean of the input sequence.

Examples#

>>> mean([1, 2, 3, 4])
2.5
kahan.sum(a)#

Return the sum of iterable `a’.

Parameters#

aiterable

Input sequence

Returns#

float

The cumulative sum of the input sequence.

Examples#

>>> sum([1, 2, 3, 4])
10.0