Changeset 6818 for branches/numpy_misc/tools/pytools/numtools.py
- Timestamp:
- Apr 16, 2009, 9:15:06 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/numpy_misc/tools/pytools/numtools.py
r18 r6818 13 13 """ 14 14 15 import types, Numeric 15 import types 16 import numpy as num 16 17 17 if type(x) == Numeric.ArrayType:18 return Numeric.sum(x)19 elif type(x) in [types.ListType, types.TupleType]:18 if isinstance(x, num.ndarray): 19 return num.sum(x) 20 elif isinstance(x, (list, tuple)): 20 21 s = x[0] 21 22 for e in x[1:]: … … 27 28 """ 28 29 29 from Numeric import dot, reshape30 import numpy as num 30 31 31 x = reshape(x, (A.shape[1], 1)) #Make x a column vector32 x = num.reshape(x, (A.shape[1], 1)) #Make x a column vector 32 33 33 return dot(A, x)34 return num.dot(A, x) 34 35 35 36 … … 49 50 """ 50 51 51 from Numeric import ones, arange, Float, multiply52 import numpy as num 52 53 53 54 d = len(N) … … 55 56 X = [] 56 57 for s in range(d): 57 local_shape = ones(d)58 local_shape = num.ones(d) 58 59 local_shape[s] = N[s] 59 a = arange(N[s])60 a = num.arange(N[s]) 60 61 if N[s] > 1: 61 a = a.astype( Float)/(N[s]-1)62 a = a.astype(num.float)/(N[s]-1) 62 63 else: 63 a = a.astype( Float)64 a = a.astype(num.float) 64 65 65 66 # Put ones in all other dimensions … … 70 71 e.append(a) 71 72 else: 72 e.append( ones(N[t]))73 e.append(num.ones(N[t])) 73 74 74 75 # Take kronecker product of all dimensions … … 76 77 x = 1 77 78 for t in range(d): 78 x= multiply.outer(x,e[t])79 x=num.multiply.outer(x,e[t]) 79 80 80 81 #print x, x.shape … … 89 90 Number of ones in mask must equal len(x).""" 90 91 91 from Numeric import sum, ArrayType, zeros92 import numpy as num 92 93 93 assert type(x) == ArrayType94 assert type(mask) == ArrayType94 assert isinstance(x, num.ndarray) 95 assert isinstance(mask, num.ndarray) 95 96 #FIXME: Assert that mask contains only ones and zeros 96 assert len(x) == sum(mask), 'Number of ones in mask must equal length of x'97 assert len(x) == num.sum(mask), 'Number of ones in mask must equal length of x' 97 98 98 99 d = len(mask) 99 y = zeros(d, x.typecode())100 y = num.zeros(d, x.dtype) 100 101 101 102 i = 0
Note: See TracChangeset
for help on using the changeset viewer.