Package qtcm :: Module where_close
[hide private]
[frames] | no frames]

Module where_close

source code

Single public function module.

See function docstring for description.


Version: 0.1.2

Date: September 12, 2008

Author: Johnny Lin

Functions [hide private]
 
where_close(x, y, rtol=1e-05, atol=1e-08)
Mask of where x and y are element-wise "equal" to each other.
source code
 
_where_close_masked(x, y, rtol=1e-05, atol=1e-08)
Version of where_close for masked arrays.
source code
 
_where_close_unmasked(x, y, rtol=1e-05, atol=1e-08)
Version of where_close for unmasked arrays.
source code
Variables [hide private]
  __credits__ = 'http://www.johnny-lin.com/py_pkgs/qtcm/'
  __test__ = {'Additional Examples': '\n '}
Function Details [hide private]

where_close(x, y, rtol=1e-05, atol=1e-08)

source code 
Mask of where x and y are element-wise "equal" to each other.

Returns an int integer array with elements equal to 1 where x
and y are "equal", and 0 otherwise.  If x or y are floating
point, "equal" means where abs(x-y) <= atol + rtol * abs(y).
This is essentially the same algorithm used in the
numpy/Numeric/numarray function allclose.  If x and y are
integer, "equal" means strict equality.  Shape and size of
output is the same as x and y; if one is an array and the other
is scalar, shape and size of the output is the same as the
array.

Output is an MA/ma masked array, unless both inputs are not
MA/ma objects, in which case output is a numpy/Numeric/numarray
array.  If inputs are both unmasked scalars the output is a
Python integer scalar.

Positional Input Arguments:
* x:  Scalar, numpy/Numeric/numarray array, MA/ma array, Python
  list/tuple of any size and shape.  Floating or integer type.
* y:  Scalar, numpy/Numeric/numarray array, MA/ma array, Python
  list/tuple of any size and shape.  Floating or integer type.

Keyword Input Arguments:
* rtol:   "Relative" tolerance.  Default is 1.e-5.  Used in the
  comparison between x and y only if the two are floating point.
* atol:   "Absolute" tolerance.  Default is 1.e-8.  Used in the
  comparison between x and y only if the two are floating point.

If either of the inputs are MA/ma masked objects, this function
uses the MA/ma default algorithm for comparison, i.e., masked
values are always considered equal.

Examples:
>>> from where_close import where_close
>>> x = [20.,  -32., -1., 2.  , 5., 29.]
>>> y = [20.1, -31., -1., 2.01, 3., 28.99]
>>> ind = where_close(x, y)
>>> ['%.1g' % ind[i] for i in range(len(ind))]
['0', '0', '1', '0', '0', '0']

>>> from where_close import where_close
>>> x = [20.,  -32., -1., 2.            , 5., 29.]
>>> y = [20.1, -31., -1., 2.000000000001, 3., 28.99]
>>> ind = where_close(x, y)
>>> ['%.1g' % ind[i] for i in range(len(ind))]
['0', '0', '1', '1', '0', '0']

>>> x = N.array([1,  5,  7, -2, 10])
>>> y = N.array([1, -5, 17, -2,  0])
>>> ind = where_close(x, y)
>>> ['%.1g' % ind[i] for i in range(len(ind))]
['1', '0', '0', '1', '0']

_where_close_masked(x, y, rtol=1e-05, atol=1e-08)

source code 

Version of where_close for masked arrays.

See docstring for where_close for details regarding parameters and function.

_where_close_unmasked(x, y, rtol=1e-05, atol=1e-08)

source code 

Version of where_close for unmasked arrays.

See docstring for where_close for details regarding parameters and function.