Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Keith Goodman
On Fri, Dec 11, 2009 at 6:38 PM, Robert Kern wrote: > On Fri, Dec 11, 2009 at 18:38, Keith Goodman wrote: > >> That seems to work. To avoid changing the input >> x = np.array(1) x.shape >>   () y = nan_to_num(x) x.shape >>   (1,) >> >> I moved y = x.copy() further up and switc

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Robert Kern
On Fri, Dec 11, 2009 at 18:38, Keith Goodman wrote: > That seems to work. To avoid changing the input > >>> x = np.array(1) >>> x.shape >   () >>> y = nan_to_num(x) >>> x.shape >   (1,) > > I moved y = x.copy() further up and switched x's to y's. Here's what > it looks like: > > def nan_to_num(x)

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Keith Goodman
On Fri, Dec 11, 2009 at 4:06 PM, Robert Kern wrote: > On Fri, Dec 11, 2009 at 17:44, Keith Goodman wrote: >> On Fri, Dec 11, 2009 at 2:22 PM, Robert Kern wrote: >>> On Fri, Dec 11, 2009 at 16:09, Keith Goodman wrote: On Fri, Dec 11, 2009 at 1:14 PM, Robert Kern wrote: > On Fri, Dec 11

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Robert Kern
On Fri, Dec 11, 2009 at 18:03, Keith Goodman wrote: > Ack! The "if issubclass(t, _nx.inexact)" fix doesn't work. It solves > the bool problem but it introduces its own problem since numpy.object_ > is not a subclass of inexact: > >>> nan_to_num([np.inf]) >   array([ Inf]) Right. This is the prob

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Robert Kern
On Fri, Dec 11, 2009 at 17:44, Keith Goodman wrote: > On Fri, Dec 11, 2009 at 2:22 PM, Robert Kern wrote: >> On Fri, Dec 11, 2009 at 16:09, Keith Goodman wrote: >>> On Fri, Dec 11, 2009 at 1:14 PM, Robert Kern wrote: On Fri, Dec 11, 2009 at 14:41, Keith Goodman wrote: > On Fri, Dec 11

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Keith Goodman
On Fri, Dec 11, 2009 at 3:44 PM, Keith Goodman wrote: > On Fri, Dec 11, 2009 at 2:22 PM, Robert Kern wrote: >> On Fri, Dec 11, 2009 at 16:09, Keith Goodman wrote: >>> On Fri, Dec 11, 2009 at 1:14 PM, Robert Kern wrote: On Fri, Dec 11, 2009 at 14:41, Keith Goodman wrote: > On Fri, Dec

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Keith Goodman
On Fri, Dec 11, 2009 at 2:22 PM, Robert Kern wrote: > On Fri, Dec 11, 2009 at 16:09, Keith Goodman wrote: >> On Fri, Dec 11, 2009 at 1:14 PM, Robert Kern wrote: >>> On Fri, Dec 11, 2009 at 14:41, Keith Goodman wrote: On Fri, Dec 11, 2009 at 12:08 PM, Bruce Southey wrote: >>> > So I ag

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Robert Kern
On Fri, Dec 11, 2009 at 16:09, Keith Goodman wrote: > On Fri, Dec 11, 2009 at 1:14 PM, Robert Kern wrote: >> On Fri, Dec 11, 2009 at 14:41, Keith Goodman wrote: >>> On Fri, Dec 11, 2009 at 12:08 PM, Bruce Southey wrote: >> So I agree that it should leave the input untouched when a non-floa

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Keith Goodman
On Fri, Dec 11, 2009 at 1:14 PM, Robert Kern wrote: > On Fri, Dec 11, 2009 at 14:41, Keith Goodman wrote: >> On Fri, Dec 11, 2009 at 12:08 PM, Bruce Southey wrote: > >>> So I agree that it should leave the input untouched when a non-float >>> dtype is used for some array-like input. >> >> Would

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Robert Kern
On Fri, Dec 11, 2009 at 14:41, Keith Goodman wrote: > On Fri, Dec 11, 2009 at 12:08 PM, Bruce Southey wrote: >> So I agree that it should leave the input untouched when a non-float >> dtype is used for some array-like input. > > Would only one line need to be changed? Would changing > > if not i

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Keith Goodman
On Fri, Dec 11, 2009 at 12:08 PM, Bruce Southey wrote: > On 12/11/2009 01:33 PM, Robert Kern wrote: >> On Fri, Dec 11, 2009 at 13:11, Bruce Southey  wrote: >> >> >>> As documented, nan_to_num returns a float so it does not return the >>> input unchanged. >>> > Sorry for my mistake: > Given an int

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Bruce Southey
On 12/11/2009 01:33 PM, Robert Kern wrote: > On Fri, Dec 11, 2009 at 13:11, Bruce Southey wrote: > > >> As documented, nan_to_num returns a float so it does not return the >> input unchanged. >> Sorry for my mistake: Given an int input, np.nan_to_num returns an int dtype >>> np.nan_to_n

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Robert Kern
On Fri, Dec 11, 2009 at 13:11, Bruce Southey wrote: > As documented, nan_to_num returns a float so it does not return the > input unchanged. I think that is describing the current behavior rather than documenting the intent of the function. Given the high level purpose of the function, to "[r]ep

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Bruce Southey
On 12/11/2009 10:21 AM, Keith Goodman wrote: > On Fri, Dec 11, 2009 at 12:50 AM, Nicolas Rougier > wrote: > >> Hello, >> >> Using both numpy 1.3.0 and 1.4.0rc1 I got the following exception using >> nan_to_num on a bool array, is that the expected behavior ? >> >> >> > import numpy

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Nicolas Rougier
I've created a ticket (#1327). Nicolas On Dec 11, 2009, at 17:21 , Keith Goodman wrote: > On Fri, Dec 11, 2009 at 12:50 AM, Nicolas Rougier > wrote: >> >> Hello, >> >> Using both numpy 1.3.0 and 1.4.0rc1 I got the following exception using >> nan_to_num on a bool array, is that the expected

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Keith Goodman
On Fri, Dec 11, 2009 at 12:50 AM, Nicolas Rougier wrote: > > Hello, > > Using both numpy 1.3.0 and 1.4.0rc1 I got the following exception using > nan_to_num on a bool array, is that the expected behavior ? > > import numpy Z = numpy.zeros((3,3),dtype=bool) numpy.nan_to_num(Z) > Trac

[Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Nicolas Rougier
Hello, Using both numpy 1.3.0 and 1.4.0rc1 I got the following exception using nan_to_num on a bool array, is that the expected behavior ? >>> import numpy >>> Z = numpy.zeros((3,3),dtype=bool) >>> numpy.nan_to_num(Z) Traceback (most recent call last): File "", line 1, in File "/usr/lib/py