Skip to main content

Transparent calculations with uncertainties on the quantities involved (aka "error propagation") ; calculation of derivatives

Project description

uncertainties allows calculation such as (0.2 +- 0.01)**2 = 0.04 +- 0.004 to be performed transparently.

Correlations between expressions are correctly taken into account (x-x is exactly zero, for instance).

Basic examples:

import uncertainties
from math import *  # Must be done *after* importing uncertainties

# Mathematical operations:
x = uncertainties.Number_with_uncert((0.20, 0.01))  # x = 0.20+-0.01
x = uncertainties.Number_with_uncert("0.20(1)")  # Other representation
print x**2  # Prints "0.04+-0.004"
print sin(x**2)  # Prints "0.0399...+-0.00399..."

print x.position_in_sigmas(0.17)  # Print "-3.0": deviation of -3 sigmas

# Access to the nominal value, and to the uncertainty:
s = x**2  # Square
print s  # Prints "0.04+-0.004"
print s.nominal_value  # Prints "0.04"
print s.std_dev()  # Prints "0.004..."

print s.derivatives[x]  # Partial derivative: prints "0.4" (= 2*0.20)

print s - x*x  # Exactly zero: correlations taken into account

The Python (or IPython) shell can thus be used as a powerful calculator that handles quantities with uncertainties (print statements are optional, and all mathematical functions can be imported with from math import * after importing this module with import uncertainties).

Almost all mathematical operations are supported, including most functions from the standard math module and functions from the third-party numpy module (fast operations on arrays and matrices). There is no restriction on the complexity of the expressions, or on the number of variables involved.

Another possible use of this module is the calculation of partial derivatives of mathematical functions.

More examples and additional information can be obtained with pydoc uncertainties after installation.

Please send feature requests, bug reports, or feedback to the author.

Installation: sudo easy_install uncertainties might work for you (this does not require any manual download). For additional installation methods, see README.txt in the provided file.

Version history (main changes only):

  • 1.0.11: origin_value was renamed more appropriately as nominal_value.

  • 1.0.9: correlations() was renamed more appropriately as covariance_matrix().

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

uncertainties-1.0.11.tar.gz (23.5 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for uncertainties-1.0.11.tar.gz
Algorithm Hash digest
SHA256 92410d8d49431830576a6c5c995685456f1ece5791c157a8950cbbbb6333d48c
MD5 adc5cffdf78177a021eb24b8db65639c
BLAKE2b-256 360c0528fc14386a0e1a3d2fe06faf31b45be7027f424c6c59be7e342bd18b8c

See more details on using hashes here.

Supported by

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