Skip to content

Commit

Permalink
more tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed Apr 30, 2024
1 parent a233ce2 commit 12b6b6b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
4 changes: 2 additions & 2 deletions doc/_templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<li>[<a href="{{ pathto('index') }}">Uncertainties</a></li>
<li>[<a href="{{ pathto('install') }}">Installation & Credits</a></li>
<li>|<a href="{{ pathto('user_guide') }}">User Guide</a></li>
<li>|<a href="{{ pathto('Formatting') }}">Formatting Values</a></li>
<li>|<a href="{{ pathto('formatting') }}">Formatting</a></li>
<li>|<a href="{{ pathto('numpy_guide') }}"> Numpy Arrays</a></li>
<li>|<a href="{{ pathto('tech_guide') }}">Technical Guide</a>]</li> &nbsp;
<li>|<a href="{{ pathto('tech_guide') }}">Advanced</a>]</li> &nbsp;
&nbsp;
&nbsp; &nbsp;
{% endblock %}
Expand Down
29 changes: 25 additions & 4 deletions doc/numpy_guide.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
.. index: NumPy support
=======================
Uncertainties in arrays
Uncertainties and numpy arrays
=======================

.. index:: unumpy
.. index:: arrays; simple use, matrices; simple use

.. _simple_array_use:

Arrays of uncertainties Variables
====================================

It is possible to put uncertainties Variable in NumPy_ arrays and
matrices:

>>> arr = numpy.array([ufloat(1, 0.01), ufloat(2, 0.1)])
>>> 2*arr
[2.0+/-0.02 4.0+/-0.2]
>>> print arr.sum()
3.00+/-0.10

Many common operations on NumPy arrays can be performed transparently
even when these arrays contain numbers with uncertainties.


The unumpy package
==================


While :ref:`basic operations on arrays <simple_array_use>` that
contain numbers with uncertainties can be performed without it, the
:mod:`unumpy` package is useful for more advanced uses.

This package contains:

1. utilities that help with the **creation and manipulation** of
Expand All @@ -17,9 +41,6 @@ NumPy_ arrays and matrices of numbers with uncertainties;
2. **generalizations** of multiple NumPy functions so that they also
work with arrays that contain numbers with uncertainties.

While :ref:`basic operations on arrays <simple_array_use>` that
contain numbers with uncertainties can be performed without it, the
:mod:`unumpy` package is useful for more advanced uses.

Operations on arrays (including their cosine, etc.) can thus be
performed transparently.
Expand Down
28 changes: 18 additions & 10 deletions doc/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ The most common and important functions for creating uncertain
Basic math with uncertain Variables
=========================================

:class:`Variables` can be used in basic mathematical calculations
:class:`Variable`s can be used in basic mathematical calculations
('+', '-', '*', '/', '**') as with other Python numbers and variables.
>>> t = ufloat(0.2, 0.01)
Expand Down Expand Up @@ -177,33 +177,46 @@ The functions in the :mod:`uncertainties.umath` module include:
Comparison operators
====================

Comparison operators ('==', '!=', '>', '<', '>=', and '<=') for values with
Comparison operators ('==', '!=', '>', '<', '>=', and '<=') for Variables with
uncertainties are somewhat complicated, and need special atention. As we
hinted at above, and will explore in more detai below and in the
:ref:`Technical Guide <comparison_operators>`, this relates to the correlation
between variables with
between Variables.



Equality and inequality comparisons
------------------------------------

If we compare the equality of two Variables with the same nominal value and
uncertainty, we see

>>> x = ufloat(5, 0.5)
>>> y = ufloat(5, 0.5)
>>> x == x
True
>>> x == y
False

While it may seem like this based on identity, note that
The difference here is that although the two Python objects have the same
nominal value and uncertainty, these are indepedent, uncorrelated values. It
is not exactly true that the difference is based on identity, note that

>>> x == (1.0*x)
True
>>> x is (1.0*x)
False

In order for the resuls of two calculations with uncertainties to be considered
equal, the nomimal value *and* the uncertainty must have the same value.
equal, the :mod:`uncertainties` package does not test whether the nomimal value
and the uncertainty have the same value. Instead it checks whether the
difference of the two calculations has a nominal value of 0 *and* an
uncertainty of 0.

>>> (x -x)
0.0+/-0
>>> (x -y)
0.0+/-0.7071067811865476


Comparisons of magnitude
Expand Down Expand Up @@ -261,11 +274,6 @@ To check whether the uncertainty is NaN or Inf, use one of :func:`math.isnan`,
``std_dev`` attribute.


.. index:: arrays; simple use, matrices; simple use

.. _simple_array_use:


.. index:: correlations; detailed example


Expand Down

0 comments on commit 12b6b6b

Please sign in to comment.