Changeset 5897 for anuga_core/source/anuga/utilities/numerical_tools.py
- Timestamp:
- Nov 6, 2008, 12:17:15 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/numerical_tools.py
r5891 r5897 7 7 from warnings import warn 8 8 9 ##from numpy import ndarray, array, sum, inner, ravel, sqrt, searchsorted, sort, concatenate, float, arange 10 import numpy 9 #Establish which Numeric package to use 10 #(this should move to somewhere central) 11 #try: 12 # from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt, 13 # searchsorted, sort, concatenate, Float, arange 14 #except: 15 # #print 'Could not find scipy - using Numeric' 16 # from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt, 17 #searchsorted, sort, concatenate, Float, arange 18 19 from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt,\ 20 searchsorted, sort, concatenate, Float, arange 11 21 12 22 # Getting an infinite number to use when using Numeric 13 23 #INF = (array([1])/0.)[0] 14 24 15 NAN = ( numpy.array([1])/0.)[0]25 NAN = (array([1])/0.)[0] 16 26 # Note, INF is used instead of NAN (Not a number), since Numeric has no NAN 17 27 # if we use a package that has NAN, this should be updated to use NAN. … … 79 89 v2 = [1.0, 0.0] # Unit vector along the x-axis 80 90 81 v1 = ensure_numeric(v1, numpy.float)82 v2 = ensure_numeric(v2, numpy.float)91 v1 = ensure_numeric(v1, Float) 92 v2 = ensure_numeric(v2, Float) 83 93 84 94 # Normalise 85 v1 = v1/ numpy.sqrt(numpy.sum(v1**2))86 v2 = v2/ numpy.sqrt(numpy.sum(v2**2))95 v1 = v1/sqrt(sum(v1**2)) 96 v2 = v2/sqrt(sum(v2**2)) 87 97 88 98 # Compute angle 89 p = numpy.inner(v1, v2)90 c = numpy.inner(v1, normal_vector(v2)) # Projection onto normal99 p = innerproduct(v1, v2) 100 c = innerproduct(v1, normal_vector(v2)) # Projection onto normal 91 101 # (negative cross product) 92 102 … … 130 140 """ 131 141 132 return numpy.array([-v[1], v[0]], numpy.float)142 return array([-v[1], v[0]], Float) 133 143 134 144 … … 140 150 """Mean value of a vector 141 151 """ 142 return(float( numpy.sum(x))/len(x))152 return(float(sum(x))/len(x)) 143 153 144 154 … … 161 171 cy = y - mean(y) 162 172 163 p = numpy.inner(cx,cy)/N173 p = innerproduct(cx,cy)/N 164 174 return(p) 165 175 … … 210 220 """ 211 221 212 y = numpy.ravel(x)213 p = numpy.sqrt(numpy.inner(y,y))222 y = ravel(x) 223 p = sqrt(innerproduct(y,y)) 214 224 return p 215 225 … … 252 262 253 263 if typecode is None: 254 ##NumPy if isinstance(A, ArrayType): 255 if type(A) == numpy.ndarray: 264 if type(A) == ArrayType: 256 265 return A 257 266 else: 258 return numpy.array(A)267 return array(A) 259 268 else: 260 ##NumPy if isinstance(A, ArrayType): 261 if type(A) == numpy.ndarray: 262 ##NumPy if A.typecode == typecode: 263 if A.dtype == typecode: 264 return numpy.array(A) #FIXME: Shouldn't this just return A? 269 if type(A) == ArrayType: 270 if A.typecode == typecode: 271 return array(A) #FIXME: Shouldn't this just return A? 265 272 else: 266 return numpy.array(A,typecode)273 return array(A,typecode) 267 274 else: 268 import types ## 269 from numpy import str ## 270 if isinstance(A, types.StringType): ## 271 return numpy.array(A, dtype=int) ## 272 return numpy.array(A, typecode) 275 return array(A,typecode) 276 273 277 274 278 … … 281 285 """ 282 286 283 n = numpy.searchsorted(numpy.sort(a), bins)284 n = numpy.concatenate( [n, [len(a)]] )287 n = searchsorted(sort(a), bins) 288 n = concatenate( [n, [len(a)]] ) 285 289 286 290 hist = n[1:]-n[:-1] 287 291 288 292 if relative is True: 289 hist = hist/float( numpy.sum(hist))293 hist = hist/float(sum(hist)) 290 294 291 295 return hist … … 297 301 """ 298 302 299 mx = numpy.max(data)300 mn = numpy.min(data)303 mx = max(data) 304 mn = min(data) 301 305 302 306 if mx == mn: 303 bins = numpy.array([mn])307 bins = array([mn]) 304 308 else: 305 309 if number_of_bins is None: 306 310 number_of_bins = 10 307 311 308 bins = numpy.arange(mn, mx, (mx-mn)/number_of_bins)312 bins = arange(mn, mx, (mx-mn)/number_of_bins) 309 313 310 314 return bins
Note: See TracChangeset
for help on using the changeset viewer.