[Numpy-discussion] Setting small numbers to zero.

Christopher Barker Chris.Barker@noaa....
Wed Mar 17 14:04:00 CDT 2010


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.

And numpy.clip() may be helpful here, though last I checked, it's 
written in Python, and thus not all that fast.



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the NumPy-Discussion mailing list