def fix(x): """ Rounds towards zero. x_rounded = fix(x) rounds the elements of x to the nearest integers towards zero. For negative numbers is equivalent to ceil and for positive to floor. """ dim = numerix.shape(x) if numerix.mlab.rank(x)==2: y = reshape(x,(1,dim[0]*dim[1]))[0] y = y.tolist() elif numerix.mlab.rank(x)==1: y = x else: y = [x] for i in range(len(y)): if y[i]>0: y[i] = floor(y[i]) else: y[i] = ceil(y[i]) if numerix.mlab.rank(x)==2: x = reshape(y,dim) elif numerix.mlab.rank(x)==0: x = y[0] return x
def fix(x): """ Rounds towards zero. x_rounded = fix(x) rounds the elements of x to the nearest integers towards zero. For negative numbers is equivalent to ceil and for positive to floor. """ dim = numerix.shape(x) if MLab.rank(x)==2: y = numerix.reshape(x,(1,dim[0]*dim[1]))[0] y = y.tolist() elif MLab.rank(x)==1: y = x else: y = [x] for i in range(len(y)): if y[i]>0: y[i] = numerix.floor(y[i]) else: y[i] = numerix.ceil(y[i]) if MLab.rank(x)==2: x = numerix.reshape(y,dim) elif MLab.rank(x)==0: x = y[0] return x