Re: [Numpy-discussion] How do I do this?

2008-08-29 Thread Stéfan van der Walt
2008/8/29 Christopher Barker <[EMAIL PROTECTED]>: > How can I do this without another line of code special casing the 0, > which isn't that big I deal, but it seems kind of ugly... > > >>> a[a==0] = min_value > >>> np.sign(a) * np.maximum(np.abs(a), min_value) > array([ 2, 2, 2, 3, 4, -5]) M

Re: [Numpy-discussion] How do I do this?

2008-08-29 Thread Christopher Barker
Alan G Isaac wrote: Alan G Isaac wrote: > Does this do what you want? > idx = np.abs(a) a[idx] = min_value > > Christopher Barker wrote: >> -1 should go to -2 > > ok then: > a[idx] = min_value*np.sign(a[idx]) > I think that's what you are saying? nope: >>> a = np.array((0, 1

Re: [Numpy-discussion] Advice on converting iterator into array efficiently

2008-08-29 Thread Alan Jackson
I tested all three offered solutions : t = table[:] # convert to structured array collections = np.unique(t['collection']) for collection in collections: cond = t['collection'] == collection energy_this_collection = t['energy'][cond] -- energies = {} for ro

Re: [Numpy-discussion] How do I do this?

2008-08-29 Thread Alan G Isaac
>>> Alan G Isaac wrote: Does this do what you want? idx = np.abs(a)>>> a[idx] = min_value Christopher Barker wrote: > -1 should go to -2 ok then: a[idx] = min_value*np.sign(a[idx]) I think that's what you are saying? Cheers, Alan Isaac __

Re: [Numpy-discussion] How do I do this?

2008-08-29 Thread Christopher Barker
Keith Goodman wrote: >> Alan G Isaac wrote: >>> Does this do what you want? >>> idx = np.abs(a)>> a[idx] = min_value >> Keith Goodman wrote: >>> If you only have integers then >>> > x >>>array([ 1, 2, -5, -1, 0]) > np.sign(x+1e-16) * np.maximum(np.abs(x), 2) >>>array([ 2., 2., -

Re: [Numpy-discussion] How do I do this?

2008-08-29 Thread Keith Goodman
On Fri, Aug 29, 2008 at 3:08 PM, Christopher Barker <[EMAIL PROTECTED]> wrote: > Alan G Isaac wrote: >> Does this do what you want? >> idx = np.abs(a)> a[idx] = min_value > > yup, that's it. I had forgotten about that kind of indexing, even though > I used it for: a[a==0] = min_value > > Keith Good

Re: [Numpy-discussion] How do I do this?

2008-08-29 Thread Christopher Barker
Alan G Isaac wrote: > Does this do what you want? > idx = np.abs(a) a[idx] = min_value out of interest, is there any performance difference between: a[np.abs(a)http://projects.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] How do I do this?

2008-08-29 Thread Christopher Barker
Alan G Isaac wrote: > Does this do what you want? > idx = np.abs(a) a[idx] = min_value yup, that's it. I had forgotten about that kind of indexing, even though I used it for: a[a==0] = min_value Keith Goodman wrote: > If you only have integers then > >>> x >array([ 1, 2, -5, -1, 0]) >>> n

Re: [Numpy-discussion] np.test() Bus error on OSX. Reopened Ticket 816

2008-08-29 Thread David Cournapeau
On Sat, Aug 30, 2008 at 2:44 AM, Christopher Burns <[EMAIL PROTECTED]> wrote: > I reopened Ticket 816: > http://scipy.org/scipy/numpy/ticket/816 > Hi Chris, Could you try to do a clean install, because when Travis and me (well, mostly Travis) look at that problem, we were both on mac os X, and I

Re: [Numpy-discussion] How do I do this?

2008-08-29 Thread Keith Goodman
On Fri, Aug 29, 2008 at 2:52 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: > On Fri, Aug 29, 2008 at 2:49 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: >> On Fri, Aug 29, 2008 at 2:35 PM, Christopher Barker >> <[EMAIL PROTECTED]> wrote: >>> HI all, >>> >>> I need to do something I thought would be si

Re: [Numpy-discussion] How do I do this?

2008-08-29 Thread Alan G Isaac
Christopher Barker wrote: > I need to do something I thought would be simple -- set > all the values of an array to some minimum. so I did this: Does this do what you want? idx = np.abs(a)http://projects.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] How do I do this?

2008-08-29 Thread Keith Goodman
On Fri, Aug 29, 2008 at 2:35 PM, Christopher Barker <[EMAIL PROTECTED]> wrote: > HI all, > > I need to do something I thought would be simple -- set all the values > of an array to some minimum. so I did this: > > >>> min_value = 2 > >>> a = np.array((1, 2, 3, 4, 5,)) > >>> np.maximum(a, min_val

Re: [Numpy-discussion] How do I do this?

2008-08-29 Thread Keith Goodman
On Fri, Aug 29, 2008 at 2:49 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: > On Fri, Aug 29, 2008 at 2:35 PM, Christopher Barker > <[EMAIL PROTECTED]> wrote: >> HI all, >> >> I need to do something I thought would be simple -- set all the values >> of an array to some minimum. so I did this: >> >>

[Numpy-discussion] How do I do this?

2008-08-29 Thread Christopher Barker
HI all, I need to do something I thought would be simple -- set all the values of an array to some minimum. so I did this: >>> min_value = 2 >>> a = np.array((1, 2, 3, 4, 5,)) >>> np.maximum(a, min_value) array([2, 2, 3, 4, 5]) all was well... then I realized that a could have negative numbe

Re: [Numpy-discussion] isn't it a bug in array.fill()?

2008-08-29 Thread Charles R Harris
On Fri, Aug 29, 2008 at 3:03 PM, Alan G Isaac <[EMAIL PROTECTED]> wrote: > Stéfan van der Walt wrote: > > At first, I also thought it might be more intuitive to return the > > output array, but then I realised that it would make it more difficult > > to realise that the operation is being performe

Re: [Numpy-discussion] isn't it a bug in array.fill()?

2008-08-29 Thread Alan G Isaac
Stéfan van der Walt wrote: > At first, I also thought it might be more intuitive to return the > output array, but then I realised that it would make it more difficult > to realise that the operation is being performed in-place. Maybe it > is good to remind programmers of what happens under the

Re: [Numpy-discussion] isn't it a bug in array.fill()?

2008-08-29 Thread Stéfan van der Walt
2008/8/29 Charles R Harris <[EMAIL PROTECTED]>: >> I like that idea. A lot of numpy functions return a reference to the >> modified array when the output array (out) is specified. > > Google up the various discussions of python sort to see why Guido doesn't > like that sort of thing. We've had that

Re: [Numpy-discussion] isn't it a bug in array.fill()?

2008-08-29 Thread Alan G Isaac
I suppose all the discussion on comp.lang.python about list methods (especially sort) is becoming relevant to this thread. Cheers, Alan Isaac ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-d

Re: [Numpy-discussion] isn't it a bug in array.fill()?

2008-08-29 Thread dmitrey
Keith Goodman wrote: > On Fri, Aug 29, 2008 at 10:51 AM, Keith Goodman <[EMAIL PROTECTED]> wrote: > >> On Fri, Aug 29, 2008 at 10:42 AM, dmitrey <[EMAIL PROTECTED]> wrote: >> >>> Keith Goodman wrote: >>> Yeah, I do stuff like that too. fill works in place so it returns None. >>>

Re: [Numpy-discussion] isn't it a bug in array.fill()?

2008-08-29 Thread Charles R Harris
On Fri, Aug 29, 2008 at 11:51 AM, Keith Goodman <[EMAIL PROTECTED]> wrote: > On Fri, Aug 29, 2008 at 10:42 AM, dmitrey <[EMAIL PROTECTED]> > wrote: > > > > Keith Goodman wrote: > >> Yeah, I do stuff like that too. fill works in place so it returns None. > >> > >> > x = np.array([1,2]) >

Re: [Numpy-discussion] isn't it a bug in array.fill()?

2008-08-29 Thread Keith Goodman
On Fri, Aug 29, 2008 at 10:51 AM, Keith Goodman <[EMAIL PROTECTED]> wrote: > On Fri, Aug 29, 2008 at 10:42 AM, dmitrey <[EMAIL PROTECTED]> wrote: >> >> Keith Goodman wrote: >>> Yeah, I do stuff like that too. fill works in place so it returns None. >>> >>> > x = np.array([1,2]) > x.fill(10)

Re: [Numpy-discussion] isn't it a bug in array.fill()?

2008-08-29 Thread Keith Goodman
On Fri, Aug 29, 2008 at 10:42 AM, dmitrey <[EMAIL PROTECTED]> wrote: > > Keith Goodman wrote: >> Yeah, I do stuff like that too. fill works in place so it returns None. >> >> x = np.array([1,2]) x.fill(10) x >>array([10, 10]) >> x = x.fill(10) # <-- Danger! print

Re: [Numpy-discussion] isn't it a bug in array.fill()?

2008-08-29 Thread dmitrey
Keith Goodman wrote: > Yeah, I do stuff like that too. fill works in place so it returns None. > > >>> x = np.array([1,2]) >>> x.fill(10) >>> x >>> >array([10, 10]) > >>> x = x.fill(10) # <-- Danger! >>> print x >>> > None > Since result "None" is never used it would be

[Numpy-discussion] np.test() Bus error on OSX. Reopened Ticket 816

2008-08-29 Thread Christopher Burns
I reopened Ticket 816: http://scipy.org/scipy/numpy/ticket/816 Running numpy.test() causes a bus error on OSX. -- Christopher Burns Computational Infrastructure for Research Labs 10 Giannini Hall, UC Berkeley phone: 510.643.4014 http://cirl.berkeley.edu/ _

Re: [Numpy-discussion] isn't it a bug in array.fill()?

2008-08-29 Thread Keith Goodman
On Fri, Aug 29, 2008 at 10:19 AM, dmitrey <[EMAIL PROTECTED]> wrote: > hi all, > isn't it a bug > (latest numpy from svn, as well as my older version) > > from numpy import array > print array((1,2,3)).fill(10) > None Yeah, I do stuff like that too. fill works in place so it returns None. >> x =

Re: [Numpy-discussion] isn't it a bug in array.fill()

2008-08-29 Thread dmitrey
sorry, it isn't a bug, it's my fault, fill() returns None and do in-place modification. D. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion

[Numpy-discussion] isn't it a bug in array.fill()?

2008-08-29 Thread dmitrey
hi all, isn't it a bug (latest numpy from svn, as well as my older version) from numpy import array print array((1,2,3)).fill(10) None Regards, D. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/nu

[Numpy-discussion] Problem with numpy in pyinstaller

2008-08-29 Thread Jeffrey Starn
I have a program that imports numpy and scipy. When I try to use PyInstaller, I get the following error: File "", line 21, in NameError: name 'io' is not defined The code up to line 21 is (line numbers differ becasue of comments): from numpy import * from numpy import random from scipy import

Re: [Numpy-discussion] Advice on converting iterator into array efficiently

2008-08-29 Thread Francesc Alted
A Friday 29 August 2008, Francesc Alted escrigué: > A Friday 29 August 2008, Alan Jackson escrigué: > > Looking for advice on a good way to handle this problem. > > > > I'm dealing with large tables (Gigabyte large). I would like to > > efficiently subset values from one column based on the values

Re: [Numpy-discussion] Advice on converting iterator into array efficiently

2008-08-29 Thread Francesc Alted
A Friday 29 August 2008, Alan Jackson escrigué: > Looking for advice on a good way to handle this problem. > > I'm dealing with large tables (Gigabyte large). I would like to > efficiently subset values from one column based on the values in > another column, and get arrays out of the operation. Fo