[Numpy-discussion] Cutoff small values of a vector to stop underflow

Rick Muller rpmuller@gmail....
Fri Sep 3 11:39:13 CDT 2010


There just *has* to be a better way of doing this. I want to cut off small
values of a vector, and I'm currently doing something like:

>>> for i in xrange(n):
>>>    if abs(A[i]) < tol: A[i] = 0

Which is slow, since A can be really long. Is there a way to write a Ufunc
that would do something like this more directly? The naive things I've tried
didn't work, e.g.

>>> def cut(a,tol=1e-10):
>>>     if less(absolute(a),tol):
>>>         a = 0
>>>     return

-- 
Rick Muller
rpmuller@gmail.com
505-750-7557
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100903/8a4d94e0/attachment.html 


More information about the NumPy-Discussion mailing list