Install & Compatibility
Where this runs
tested against v3.2.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.056s · 18.1MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.050s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ufloat
✓ from uncertainties import ufloat
umath
✓ from uncertainties.umath import sin, cos
Provides mathematical functions for `ufloat` objects. Some functions are deprecated as of 3.2.2.
unumpy
✓ from uncertainties import unumpy
Provides NumPy-like array and matrix operations for `ufloat` objects. `unumpy.umatrix` is deprecated.
Create numbers with uncertainties using `ufloat` and perform standard arithmetic or mathematical operations, with uncertainties automatically propagated.
from uncertainties import ufloat
from uncertainties.umath import sin
x = ufloat(2, 0.1) # x = 2 +/- 0.1
y = ufloat(3, 0.2) # y = 3 +/- 0.2
result_sum = x + y
result_product = x * y
result_sin = sin(x)
print(f"Sum: {result_sum}")
print(f"Product: {result_product}")
print(f"Sin(x): {result_sin}")
# Accessing nominal value and standard deviation
print(f"Nominal value of sum: {result_sum.nominal_value}")
print(f"Standard deviation of sum: {result_sum.std_dev}")
Debug
Known issues
breakingVersion 4.0.0 is under development and will introduce significant breaking changes, notably making `UFloat` objects immutable. Plan for migration once 4.0 is released.fixReview the 4.0.0 release notes and documentation upon release for specific migration instructions.
affects: Future (4.0.0+)
breakingThe handling of `numpy` as an optional dependency changed in version 3.2.3. Previously, importing a `numpy`-dependent function without `numpy` installed would raise an `ImportError`. Now, such functions can be imported, but attempting to execute them will raise a `NotImplementedError`.fixEnsure `numpy` is installed (`pip install numpy`) if you intend to use `uncertainties.unumpy` or other `numpy`-dependent features.
affects: >=3.2.3
deprecated`uncertainties.unumpy.umatrix` is deprecated as of version 3.2.2 and will be removed in version 4.0. This aligns with the broader discouragement of `numpy.matrix` in NumPy itself.fixReplace usage of `unumpy.umatrix` with `unumpy.uarray` and standard NumPy array operations on `ufloat` objects, which are well-supported.
affects: >=3.2.2 (removal in 4.0.0+)
deprecatedSeveral functions in `uncertainties.umath` (e.g., `ceil`, `fabs`, `floor`, `trunc`) and methods on `AffineScalarFunc`/`UFloat` objects (e.g., `__floordiv__`, `__mod__`, `__abs__`) were deprecated in 3.2.2 and will be removed in a future release.fixConsult the `uncertainties` documentation for alternatives or use standard Python operations where applicable.
affects: >=3.2.2
gotchaAs of version 3.2.4, the stacklevel of the warning for `std_dev==0` has been increased. This means the warning will now point to the user's calling code rather than `ufloat()`, making it easier to diagnose the source of zero standard deviation inputs.fixReview code for instances where `ufloat` is initialized with a standard deviation of zero if unexpected warnings appear.
affects: >=3.2.4
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'uncertainties'
The `uncertainties` package is not installed in the current Python environment or is not accessible on the PYTHONPATH.
fixInstall the package using pip: `pip install uncertainties`
TypeError: a float is required
Standard `math` module functions do not know how to handle `ufloat` objects directly, expecting a standard float.
fixUse functions from `uncertainties.umath` (e.g., `umath.sin`) or wrap the original function with `uncertainties.wrap()`.
AttributeError: 'ufloat' object has no attribute 'value'
Users often guess attribute names for accessing the nominal value or standard deviation of a `ufloat` object.
fixAccess the nominal value using `.n` and the standard deviation (uncertainty) using `.s` (e.g., `my_ufloat_obj.n`, `my_ufloat_obj.s`).
TypeError: 'list' object cannot be interpreted as an uncertainty value
The `ufloat` constructor expects a single numerical value and its single uncertainty, not a list of values or uncertainties.
fixTo create an array of uncertain numbers, use `uncertainties.unumpy.uarray` with separate lists for nominal values and uncertainties, or create a list of individual `ufloat` objects.
Upgrade
Version history
3.2.3latest on PyPI · released Apr 21, 2025
Audit
Dependencies
numpyoptionalOptional dependency for array and matrix operations (unumpy submodule), not required for core functionality.