[Numpy-discussion] Setting small numbers to zero.

Friedrich Romstedt friedrichromstedt@gmail....
Wed Mar 17 12:50:30 CDT 2010


Code:

import numpy
import time

a = numpy.random.random((2000, 2000))

start = time.time()
a[abs(a) < 10] = 0
stop = time.time()

print stop - start

a = numpy.random.random((2000, 2000))

start = time.time()
a = a * (abs(a) >= 10)
stop = time.time()

print stop - start

a = numpy.random.random((2000, 2000))

start = time.time()
a *= (abs(a) >= 10)
stop = time.time()

print stop - start


Output (reproducible):

0.680999994278
0.220999956131
0.19000005722

Friedrich


More information about the NumPy-Discussion mailing list