Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Robert Kern
On Wed, Mar 17, 2010 at 14:18, Keith Goodman wrote: > On Wed, Mar 17, 2010 at 12:08 PM, Robert Kern wrote: >> On Wed, Mar 17, 2010 at 14:03, Keith Goodman wrote: >>> On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker >>> wrote: Friedrich Romstedt wrote: > Code: > > import num

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread josef . pktd
On Wed, Mar 17, 2010 at 3:11 PM, Robert Kern wrote: > On Wed, Mar 17, 2010 at 14:07,   wrote: >> On Wed, Mar 17, 2010 at 3:01 PM, Robert Kern wrote: >>> On Wed, Mar 17, 2010 at 14:04, Christopher Barker >>> wrote: Friedrich Romstedt wrote: > Code: > > import numpy > import

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Keith Goodman
On Wed, Mar 17, 2010 at 12:08 PM, Robert Kern wrote: > On Wed, Mar 17, 2010 at 14:03, Keith Goodman wrote: >> On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker >> wrote: >>> Friedrich Romstedt wrote: Code: import numpy import time a = numpy.random.random((2000, 2

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Christopher Barker
Robert Kern wrote: > On Wed, Mar 17, 2010 at 14:04, Christopher Barker > wrote: >> though last I checked, it's >> written in Python, > > No, it isn't. > >> and thus not all that fast. > > No, it's reasonably performant. nice to know -- a good while back, I wrote a small collection of add-ons

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Robert Kern
On Wed, Mar 17, 2010 at 14:07, wrote: > On Wed, Mar 17, 2010 at 3:01 PM, Robert Kern wrote: >> On Wed, Mar 17, 2010 at 14:04, Christopher Barker >> wrote: >>> Friedrich Romstedt wrote: Code: import numpy import time a = numpy.random.random((2000, 2000))

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Robert Kern
On Wed, Mar 17, 2010 at 14:03, Keith Goodman wrote: > On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker > wrote: >> Friedrich Romstedt wrote: >>> Code: >>> >>> import numpy >>> import time >>> >>> a = numpy.random.random((2000, 2000)) >>> >>> start = time.time() >>> a[abs(a) < 10] = 0 >>> stop

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread josef . pktd
On Wed, Mar 17, 2010 at 3:01 PM, Robert Kern wrote: > On Wed, Mar 17, 2010 at 14:04, Christopher Barker > wrote: >> Friedrich Romstedt wrote: >>> Code: >>> >>> import numpy >>> import time >>> >>> a = numpy.random.random((2000, 2000)) >>> >>> start = time.time() >>> a[abs(a) < 10] = 0 >>> stop =

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Keith Goodman
On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker 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" funct

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Robert Kern
On Wed, Mar 17, 2010 at 14:04, Christopher Barker 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

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Christopher Barker
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

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Friedrich Romstedt
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((2

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread josef . pktd
On Wed, Mar 17, 2010 at 11:56 AM, Keith Goodman wrote: > On Wed, Mar 17, 2010 at 8:51 AM, gerardob wrote: >> >> How can i modified all the values of a numpy array whose value is smaller >> than a given epsilon to zero? >> >> Example >> epsilon=0.01 >> a = [[0.003,2][23,0.0001]] >> >> output: >> [

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Keith Goodman
On Wed, Mar 17, 2010 at 8:51 AM, gerardob wrote: > > How can i modified all the values of a numpy array whose value is smaller > than a given epsilon to zero? > > Example > epsilon=0.01 > a = [[0.003,2][23,0.0001]] > > output: > [[0,2][23,0]] Here's one way: >> a = np.array([[0.003,2],[23,0.0001

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Alan McIntyre
On Wed, Mar 17, 2010 at 8:51 AM, gerardob wrote: > How can i modified all the values of a numpy array whose value is smaller > than a given epsilon to zero? > > Example > epsilon=0.01 > a = [[0.003,2][23,0.0001]] > > output: > [[0,2][23,0]] Give this a try: >>> import numpy as np >>> epsilon=0.0

[Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread gerardob
How can i modified all the values of a numpy array whose value is smaller than a given epsilon to zero? Example epsilon=0.01 a = [[0.003,2][23,0.0001]] output: [[0,2][23,0]] -- View this message in context: http://old.nabble.com/Setting-small-numbers-to-zero.-tp27933569p27933569.html Sent f