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

Rick Muller rpmuller at gmail.com
Fri Sep 3 12:49:21 EDT 2010


Sweet! Guess I need to learn more about numpy indexing: this is pretty
powerful.

On Fri, Sep 3, 2010 at 10:42 AM, Keith Goodman <kwgoodman at gmail.com> wrote:

> On Fri, Sep 3, 2010 at 9:39 AM, Rick Muller <rpmuller at 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
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Rick Muller
rpmuller at gmail.com
505-750-7557
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100903/c9b3d4fd/attachment.html>


More information about the NumPy-Discussion mailing list