Changeset 7276 for anuga_core/source/anuga/utilities/where_close.py
- Timestamp:
- Jun 30, 2009, 2:07:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/where_close.py
r5681 r7276 62 62 y are "equal", and 0 otherwise. If x or y are floating point, 63 63 "equal" means where abs(x-y) <= atol + rtol * abs(y). This is 64 essentially the same algorithm used in the Numeric function64 essentially the same algorithm used in the numeric function 65 65 allclose. If x and y are integer, "equal" means strict equality. 66 66 Shape and size of output is the same as x and y; if one is an 67 67 array and the other is scalar, shape and size of the output is the 68 same as the array. Output is a Numeric array, unless both inputs68 same as the array. Output is a numeric array, unless both inputs 69 69 are scalar in which the output is a Python integer scalar. 70 70 71 71 Positional Input Arguments: 72 * x: Scalar or Numeric array, Python list/tuple of any size and72 * x: Scalar or numeric array, Python list/tuple of any size and 73 73 shape. Floating or integer type. 74 * y: Scalar or Numeric array, Python list/tuple of any size and74 * y: Scalar or numeric array, Python list/tuple of any size and 75 75 shape. Floating or integer type. 76 76 … … 84 84 85 85 Examples: 86 >>> import Numericas N86 >>> import numpy as N 87 87 >>> from where_close import where_close 88 88 >>> x = [20., -32., -1., 2. , 5., 29.] … … 98 98 ['1', '0', '0', '1', '0'] 99 99 """ 100 import Numericas N100 import numpy as N 101 101 abs = N.absolute 102 102 103 103 104 #- Make sure input is Numeric type:104 #- Make sure input is numeric type: 105 105 106 106 xN = N.array(x) … … 111 111 # type returns an error: 112 112 113 if (xN. typecode()in N.typecodes['Float']) or \114 (yN. typecode()in N.typecodes['Float']):113 if (xN.dtype.char in N.typecodes['Float']) or \ 114 (yN.dtype.char in N.typecodes['Float']): 115 115 return N.less_equal(abs(xN-yN), atol+rtol*abs(yN)) 116 116 117 elif (xN. typecode()in N.typecodes['Integer']) and \118 (yN. typecode()in N.typecodes['Integer']):117 elif (xN.dtype.char in N.typecodes['Integer']) and \ 118 (yN.dtype.char in N.typecodes['Integer']): 119 119 return N.equal(xN, yN) 120 120 … … 132 132 """ 133 133 >>> from where_close import where_close 134 >>> import Numericas N134 >>> import numpy as N 135 135 >>> x = [20., -32., -1., 2. , 5., 29.] 136 136 >>> y = [20.1, -31., -1., 2.000000000001, 3., 28.99] … … 144 144 >>> ind.shape 145 145 (2, 3) 146 >>> ind. typecode()147 ' l'146 >>> ind.dtype.char 147 '?' 148 148 >>> type(ind) 149 <type ' array'>149 <type 'numpy.ndarray'> 150 150 151 151 >>> x = [20., -32., -1., 2. , 5., 29.] … … 179 179 0 180 180 >>> type(ind) 181 <type ' int'>181 <type 'numpy.bool_'> 182 182 >>> x = -33 183 183 >>> y = -33.
Note: See TracChangeset
for help on using the changeset viewer.