[Numpy-discussion] Setting small numbers to zero.

Keith Goodman kwgoodman at gmail.com
Wed Mar 17 15:03:28 EDT 2010


On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker
<Chris.Barker at noaa.gov> wrote:
> Friedrich Romstedt wrote:
>> Code:
>>
>> import numpy
>> import time
>>
>> a = numpy.random.random((2000, 2000))
>>
>> start = time.time()
>> a[abs(a) < 10] = 0
>> stop = time.time()
>
> I highly recommend ipython and its "timeit" function --much better for this.

One of the methods, the fast one, uses an in-place operation, so
timeit won't work. But for cases where timeit does work, yes, it is
great.



More information about the NumPy-Discussion mailing list