Ignore:
Timestamp:
Apr 16, 2009, 9:15:06 AM (16 years ago)
Author:
rwilson
Message:

Numeric to numpy conversion.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/numpy_misc/tools/pytools/numtools.py

    r18 r6818  
    1313  """
    1414
    15   import types, Numeric
     15  import types
     16  import numpy as num
    1617 
    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)):
    2021    s = x[0]
    2122    for e in x[1:]:
     
    2728  """
    2829
    29   from Numeric import dot, reshape
     30  import numpy as num
    3031
    31   x = reshape(x, (A.shape[1], 1)) #Make x a column vector             
     32  x = num.reshape(x, (A.shape[1], 1)) #Make x a column vector             
    3233
    33   return dot(A, x)
     34  return num.dot(A, x)
    3435
    3536
     
    4950  """
    5051 
    51   from Numeric import ones, arange, Float, multiply
     52  import numpy as num
    5253
    5354  d = len(N)
     
    5556  X = []
    5657  for s in range(d):
    57     local_shape = ones(d)
     58    local_shape = num.ones(d)
    5859    local_shape[s] = N[s]
    59     a = arange(N[s])
     60    a = num.arange(N[s])
    6061    if N[s] > 1:
    61       a = a.astype(Float)/(N[s]-1)
     62      a = a.astype(num.float)/(N[s]-1)
    6263    else:
    63       a = a.astype(Float)
     64      a = a.astype(num.float)
    6465   
    6566    # Put ones in all other dimensions
     
    7071        e.append(a)
    7172      else:
    72         e.append(ones(N[t]))
     73        e.append(num.ones(N[t]))
    7374   
    7475    # Take kronecker product of all dimensions
     
    7677    x = 1 
    7778    for t in range(d):
    78       x=multiply.outer(x,e[t])
     79      x=num.multiply.outer(x,e[t])
    7980
    8081    #print x, x.shape
     
    8990     Number of ones in mask must equal len(x)."""
    9091
    91   from Numeric import sum, ArrayType, zeros
     92  import numpy as num
    9293
    93   assert type(x) == ArrayType
    94   assert type(mask) == ArrayType
     94  assert isinstance(x, num.ndarray)
     95  assert isinstance(mask, num.ndarray)
    9596  #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'
    9798
    9899  d = len(mask)
    99   y = zeros(d, x.typecode())
     100  y = num.zeros(d, x.dtype)
    100101
    101102  i = 0
Note: See TracChangeset for help on using the changeset viewer.