| |
- where_close(x, y, rtol=1.0000000000000001e-05, atol=1e-08)
- Mask of where x and y are element-wise "equal" to each other.
Returns a long 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 Numeric 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 a Numeric array, unless both inputs
are scalar in which the output is a Python integer scalar.
Positional Input Arguments:
* x: Scalar or Numeric array, Python list/tuple of any size and
shape. Floating or integer type.
* y: Scalar or Numeric 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.
Examples:
>>> import Numeric as N
>>> 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']
|