Skip to main content

calculations with values with uncertainties, error propagation

Project description

https://readthedocs.org/projects/uncertainties/badge/?version=latest https://img.shields.io/pypi/v/uncertainties.svg https://pepy.tech/badge/uncertainties/week https://codecov.io/gh/lmfit/uncertainties/branch/master/graph/badge.svg https://img.shields.io/github/actions/workflow/status/lmfit/uncertainties/python-package.yml?logo=github%20actions

The uncertainties package allows calculations with values that have uncertaintes, such as (2 +/- 0.1)*2 = 4 +/- 0.2. uncertainties takes the pain and complexity out of error propagation and calculations of values with uncertainties. For more information, see https://uncertainties.readthedocs.io/

Basic examples

>>> from uncertainties import ufloat
>>> x = ufloat(2, 0.25)
>>> x
2.0+/-0.25

>>> square = x**2
>>> square
4.0+/-1.0
>>> square.nominal_value
4.0
>>> square.std_dev  # Standard deviation
1.0

>>> square - x*x
0.0  # Exactly 0: correlations taken into account

>>> from uncertainties.umath import sin, cos  # and many more.
>>> sin(1+x**2)
-0.95892427466313845+/-0.2836621854632263

>>> print (2*x+1000).derivatives[x]  # Automatic calculation of derivatives
2.0

>>> from uncertainties import unumpy  # Array manipulation
>>> varr = unumpy.uarray([1, 2], [0.1, 0.2])
>>> print(varr)
[1.0+/-0.1 2.0+/-0.2]
>>> print(varr.mean())
1.50+/-0.11
>>> print(unumpy.cos(varr))
[0.540302305868+/-0.0841470984808 -0.416146836547+/-0.181859485365]

Main features

  • Transparent calculations with uncertainties: Liittle or no modification of existing code is needed to convert calculations of floats to calculations of values with uncertainties.

  • Correlations between expressions are correctly taken into account. Thus, x-x is exactly zero.

  • Most mathematical operations are supported, including most functions from the standard math module (sin,…). Comparison operators (>, ==, etc.) are supported too.

  • Many fast operations on arrays and matrices of numbers with uncertainties are supported.

  • Extensive support for printing numbers with uncertainties (including LaTeX support and pretty-printing).

  • Most uncertainty calculations are performed analytically.

  • This module also gives access to the derivatives of any mathematical expression (they are used by error propagation theory, and are thus automatically calculated by this module).

Installation or upgrade

To install uncertainties, use:

pip install uncertainties

To upgrade from an older version, use:

pip install --upgrade uncertainties

Further details are in the on-line documentation.

Git branches

The GitHub master branch is the latest development version, and is intended to be a stable pre-release version. It will be experimental, but should pass all tests.. Tagged releases will be available on GitHub, and correspond to the releases to PyPI. The GitHub gh-pages branch will contain a stable test version of the documentation that can be viewed at https://lmfit.github.io/uncertainties/. Other Github branches should be treated as unstable and in-progress development branches.

License

This package and its documentation are released under the Revised BSD License.

History

This package was created back around 2009 by Eric O. LEBIGOT.

Ownership of the package was taken over by the lmfit GitHub organization in 2024.

Project details


Release history Release notifications | RSS feed

This version

3.2.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uncertainties-3.2.2.tar.gz (143.9 kB view details)

Uploaded Source

Built Distribution

uncertainties-3.2.2-py3-none-any.whl (58.3 kB view details)

Uploaded Python 3

File details

Details for the file uncertainties-3.2.2.tar.gz.

File metadata

  • Download URL: uncertainties-3.2.2.tar.gz
  • Upload date:
  • Size: 143.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.5

File hashes

Hashes for uncertainties-3.2.2.tar.gz
Algorithm Hash digest
SHA256 e62c86fdc64429828229de6ab4e11466f114907e6bd343c077858994cc12e00b
MD5 d52c9e535ddd1b7a8bacdb095656d61d
BLAKE2b-256 a0b0f926a3faf468b9784bdecb8d9328b531743937ead284b2e8d406d96e8b0f

See more details on using hashes here.

File details

Details for the file uncertainties-3.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for uncertainties-3.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fd8543355952f4052786ed4150acaf12e23117bd0f5bd03ea07de466bce646e7
MD5 a70ebcb4886fe5c6bc92d2ffcfe4ca70
BLAKE2b-256 fafc97711d2a502881d871e3cf2d2645e21e7f8e4d4fd9a56937557790cade6a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page