Package ComboCode :: Package cc :: Package ivs :: Package units :: Package uncertainties :: Package unumpy
[hide private]
[frames] | no frames]

Package unumpy

source code


Utilities for NumPy arrays and matrices that contain numbers with
uncertainties.

This package contains:

1) utilities that help with the creation and manipulation of 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.

- Arrays of numbers with uncertainties can be built as follows:

  arr = unumpy.uarray(([1, 2], [0.01, 0.002]))  # (values, uncertainties)

NumPy arrays of numbers with uncertainties can also be built directly
through NumPy, thanks to NumPy's support of arrays of arbitrary objects:

  arr = numpy.array([uncertainties.ufloat((1, 0.1)),...])
  
- Matrices of numbers with uncertainties are best created in one of
two ways:

  mat = unumpy.umatrix(([1, 2], [0.01, 0.002]))  # (values, uncertainties)

Matrices can also be built by converting arrays of numbers with
uncertainties, through the unumpy.matrix class:

  mat = unumpy.matrix(arr)

unumpy.matrix objects behave like numpy.matrix objects of numbers with
uncertainties, but with better support for some operations (such as
matrix inversion):

  # The inverse or pseudo-inverse of a unumpy.matrix can be calculated:
  print mat.I  # Would not work with numpy.matrix([[ufloat(...),...]]).I

- Nominal values and uncertainties of arrays can be directly accessed:

  print unumpy.nominal_values(arr)  # [ 1.  2.]
  print unumpy.std_devs(mat)  # [ 0.01   0.002]

- This module defines uncertainty-aware mathematical functions that
generalize those from uncertainties.umath so that they work on NumPy
arrays of numbers with uncertainties instead of just scalars:

  print unumpy.cos(arr)  # Array with the cosine of each element

NumPy's function names are used, and not those of the math module (for
instance, unumpy.arccos is defined, like in NumPy, and is not named
acos like in the standard math module).

The definitions of the mathematical quantities calculated by these
functions are available in the documentation of uncertainties.umath.

- The unumpy.ulinalg module contains more uncertainty-aware functions
for arrays that contain numbers with uncertainties (see the
documentation for this module).

This module requires the NumPy package.

(c) 2009-2010 by Eric O. LEBIGOT (EOL) <eric.lebigot@normalesup.org>.
Please send feature requests, bug reports, or feedback to this address.

This software is released under a dual license.  (1) The BSD license.
(2) Any other license, as long as it is obtained from the original
author.

Submodules [hide private]

Classes [hide private]
  matrix
Class equivalent to numpy.matrix, but that behaves better when the matrix contains numbers with uncertainties.
Functions [hide private]
 
nominal_values(arr)
Returns the nominal values of the numbers in NumPy array arr.
source code
 
std_devs(arr)
Returns the standard deviations of the numbers in NumPy array arr.
source code
 
uarray((values, std_devs))
Returns a NumPy array of numbers with uncertainties initialized with the given nominal values and standard deviations.
source code
 
umatrix(*args)
Constructs a matrix that contains numbers with uncertainties.
source code
Variables [hide private]
  __all__ = core.__all__
  __package__ = 'ComboCode.cc.ivs.units.uncertainties.unumpy'
  arccos = <numpy.lib.function_base.vectorize object at 0x10bb64...
  arccosh = <numpy.lib.function_base.vectorize object at 0x10bb6...
  arcsin = <numpy.lib.function_base.vectorize object at 0x10bb64...
  arctan = <numpy.lib.function_base.vectorize object at 0x10bb64...
  arctan2 = <numpy.lib.function_base.vectorize object at 0x10bb6...
  arctanh = <numpy.lib.function_base.vectorize object at 0x10bb6...
  asinh = <numpy.lib.function_base.vectorize object at 0x10bb64290>
  ceil = <numpy.lib.function_base.vectorize object at 0x10bb64390>
  copysign = <numpy.lib.function_base.vectorize object at 0x10bb...
  cos = <numpy.lib.function_base.vectorize object at 0x10bb64410>
  cosh = <numpy.lib.function_base.vectorize object at 0x10bb64450>
  degrees = <numpy.lib.function_base.vectorize object at 0x10bb6...
  erf = <numpy.lib.function_base.vectorize object at 0x10bb644d0>
  erfc = <numpy.lib.function_base.vectorize object at 0x10bb64510>
  exp = <numpy.lib.function_base.vectorize object at 0x10bb64550>
  expm1 = <numpy.lib.function_base.vectorize object at 0x10bb64590>
  fabs = <numpy.lib.function_base.vectorize object at 0x10bb645d0>
  floor = <numpy.lib.function_base.vectorize object at 0x10bb64610>
  fmod = <numpy.lib.function_base.vectorize object at 0x10bb64650>
  gamma = <numpy.lib.function_base.vectorize object at 0x10bb64690>
  hypot = <numpy.lib.function_base.vectorize object at 0x10bb646d0>
  isinf = <numpy.lib.function_base.vectorize object at 0x10bb64710>
  isnan = <numpy.lib.function_base.vectorize object at 0x10bb64750>
  ldexp = <numpy.lib.function_base.vectorize object at 0x10bb64ad0>
  lgamma = <numpy.lib.function_base.vectorize object at 0x10bb64...
  log = <numpy.lib.function_base.vectorize object at 0x10bb647d0>
  log10 = <numpy.lib.function_base.vectorize object at 0x10bb64810>
  log1p = <numpy.lib.function_base.vectorize object at 0x10bb64850>
  modf = <numpy.lib.function_base.vectorize object at 0x10bb64a90>
  pow = <numpy.lib.function_base.vectorize object at 0x10bb64890>
  radians = <numpy.lib.function_base.vectorize object at 0x10bb6...
  sin = <numpy.lib.function_base.vectorize object at 0x10bb64910>
  sinh = <numpy.lib.function_base.vectorize object at 0x10bb64950>
  sqrt = <numpy.lib.function_base.vectorize object at 0x10bb64990>
  tan = <numpy.lib.function_base.vectorize object at 0x10bb649d0>
  tanh = <numpy.lib.function_base.vectorize object at 0x10bb64a10>
  trunc = <numpy.lib.function_base.vectorize object at 0x10bb64a50>
Function Details [hide private]

nominal_values(arr)

source code 

Returns the nominal values of the numbers in NumPy array arr.

Elements that are not uncertainties.AffineScalarFunc are passed through untouched (because a numpy.array can contain numbers with uncertainties and pure floats simultaneously).

If arr is of type unumpy.matrix, the returned array is a numpy.matrix, because the resulting matrix does not contain numbers with uncertainties.

std_devs(arr)

source code 

Returns the standard deviations of the numbers in NumPy array arr.

Elements that are not uncertainties.AffineScalarFunc are given a zero uncertainty ((because a numpy.array can contain numbers with uncertainties and pure floats simultaneously)..

If arr is of type unumpy.matrix, the returned array is a numpy.matrix, because the resulting matrix does not contain numbers with uncertainties.

uarray((values, std_devs))

source code 

Returns a NumPy array of numbers with uncertainties initialized with the given nominal values and standard deviations.

values, std_devs -- valid arguments for numpy.array, with identical shapes (list of numbers, list of lists, numpy.ndarray, etc.).

umatrix(*args)

source code 

Constructs a matrix that contains numbers with uncertainties.

The input data is the same as for uarray(...): a tuple with the nominal values, and the standard deviations.

The returned matrix can be inverted, thanks to the fact that it is a unumpy.matrix object instead of a numpy.matrix one.


Variables Details [hide private]

arccos

Value:
<numpy.lib.function_base.vectorize object at 0x10bb64190>

arccosh

Value:
<numpy.lib.function_base.vectorize object at 0x10bb64210>

arcsin

Value:
<numpy.lib.function_base.vectorize object at 0x10bb64250>

arctan

Value:
<numpy.lib.function_base.vectorize object at 0x10bb642d0>

arctan2

Value:
<numpy.lib.function_base.vectorize object at 0x10bb64310>

arctanh

Value:
<numpy.lib.function_base.vectorize object at 0x10bb64350>

copysign

Value:
<numpy.lib.function_base.vectorize object at 0x10bb643d0>

degrees

Value:
<numpy.lib.function_base.vectorize object at 0x10bb64490>

lgamma

Value:
<numpy.lib.function_base.vectorize object at 0x10bb64790>

radians

Value:
<numpy.lib.function_base.vectorize object at 0x10bb648d0>