[Numpy-discussion] Setting small numbers to zero.

Robert Kern robert.kern@gmail....
Wed Mar 17 14:01:04 CDT 2010


On Wed, Mar 17, 2010 at 14:04, Christopher Barker <Chris.Barker@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.
>
> And numpy.clip() may be helpful here,

No, it's not.

> though last I checked, it's
> written in Python,

No, it isn't.

> and thus not all that fast.

No, it's reasonably performant.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the NumPy-Discussion mailing list