Uncertainties

The uncertainties package is an open source Python library for doing calculations on numbers that have uncertainties (like 3.14±0.01) that are common in many scientific fields. The calculations done with this package will propagate the uncertainties to the result of mathematical calculations. The uncertainties package takes the pain and complexity out of uncertainty calculations and error propagation. Here is a quick taste of how to use uncertainties:

>>> from uncertainties import ufloat
>>> x = ufloat(2, 0.1)   # x = 2+/-0.1
>>> y = ufloat(3, 0.2)   # y = 3+/-0.2
>>> print(2*x)
4.00+/-0.20
>>> print(x+y)
5.00+/-0.22
>>> print(x*y)
6.0+/-0.5

The uncertainties library calculates uncertainties using linear error propagation theory by automatically calculating derivatives and analytically propagating these to the results. Correlations between variables are automatically handled. This library can also yield the derivatives of any expression with respect to the variables that have uncertain values. For other approaches, see soerp (using higher-order terms) and mcerp (using a Monte-Carlo approach).

The source code for the uncertainties package is licensed under the Revised BSD License. This documentation is licensed under the CC-SA-3 License.

Table of Contents