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

Keith Goodman kwgoodman@gmail....
Fri Sep 3 11:42:22 CDT 2010


On Fri, Sep 3, 2010 at 9:39 AM, Rick Muller <rpmuller@gmail.com> wrote:
> 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.

A[np.absolute(A) < tol] = 0


More information about the NumPy-Discussion mailing list