uncertainties

calculations with values with uncertainties, error propagation

Revised BSD License 83 个版本 Python >=3.8
安装
pip install uncertainties
poetry add uncertainties
pipenv install uncertainties
conda install uncertainties
描述

uncertainties

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

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

.. code-block:: python

>>> 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: Little 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 <https://uncertainties.readthedocs.io/en/latest/install.html>_.

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 <LICENSE.txt>_.

History

.. Note from Eric Lebigot: I would like the origin of the package to remain documented for its whole life. Thanks!

This package was created back around 2009 by Eric O. LEBIGOT <https://github.com/lebigot>_.

Ownership of the package was taken over by the lmfit GitHub organization <https://github.com/lmfit>_ in 2024.

.. _IPython: https://ipython.readthedocs.io/en/stable/ .. _math: https://docs.python.org/library/math.html .. _error propagation theory: https://en.wikipedia.org/wiki/Propagation_of_uncertainty .. _main website: https://uncertainties.readthedocs.io/

版本列表
3.2.4 2026-01-09
3.2.3 2025-04-21
3.2.2 2024-07-07
3.2.1 2024-06-08
3.2.0 2024-06-03
3.1.7 2022-06-19
3.1.6 2021-07-11
3.1.5 2020-11-18
3.1.4 2020-06-06
3.1.2 2019-08-05
3.1.1 2019-05-30
3.1 2019-05-19
3.0.3 2018-10-28
3.0.2 2018-01-14
3.0.1 2016-08-15
3.0
2.4.8.1 2016-03-28
2.4.8 2016-02-24
2.4.7.1 2016-01-16
2.4.6.1 2014-08-14
2.4.6 2014-08-14
2.4.5 2014-04-09
2.4.4 2014-01-11
2.4.3 2013-12-07
2.4.2 2013-11-19
2.4.1 2013-07-26
2.4 2013-07-18
2.3.6 2013-04-28
2.3.5 2013-04-26
2.3 2013-04-23
2.2 2013-04-18
2.1 2013-04-17
2.0.1 2013-04-14
2.0 2013-04-13
1.9.1 2013-03-01
1.9 2012-11-23
1.8 2011-10-29
1.7.4 2011-07-09
1.7.3 2011-06-19
1.7.2 2011-04-26
1.7.1 2011-03-18
1.7 2010-08-25
1.6 2010-08-15
1.5.5 2010-07-11
1.5.4.9 2010-06-30
1.5.4.8 2010-06-28
1.5.4.7 2010-06-28
1.5.4.6 2010-06-28
1.5.4.5 2010-06-28
1.5.4.4 2010-06-25
1.5.4.3 2010-06-21
1.5.4.2 2010-06-20
1.5.4.1 2010-06-08
1.5.4 2010-06-08
1.5.3 2010-06-08
1.4.5 2010-06-08
1.4.3 2010-06-08
1.4.1 2010-06-08
1.4 2010-06-08
1.3 2010-06-08
1.2.5 2010-06-08
1.2.4 2010-06-08
1.2.3 2010-06-08
1.2.2 2010-06-08
1.2.1 2010-06-08
1.2 2010-06-08
1.1 2010-06-08
1.0.17 2010-06-08
1.0.15 2010-06-08
1.0.14 2010-06-08
1.0.12 2010-06-08
1.0.11 2010-06-08
1.0.10 2010-06-08
1.0.9 2010-06-08
1.0.8 2010-06-08
1.0.7 2010-06-08
1.0.6 2010-06-08
1.0.5 2010-06-08
1.0.4 2010-06-08
1.0.2 2010-06-08
1.0.1 2010-06-08
1.0 2010-06-08