Re: [Numpy-discussion] Difference between shape=() and shape=(1,)

2010-07-17 Thread Friedrich Romstedt
2010/7/14 John Reid : > That sounds useful but I should have said: sometimes I need to replace > other values that aren't NaNs. Sorry, for the double dumb recommendation of nan_to_num, but when replacing other normal values mabe you can use: >>> a = numpy.asarray(1) >>> b = numpy.asarray([10, 1])

Re: [Numpy-discussion] Difference between shape=() and shape=(1,)

2010-07-17 Thread Friedrich Romstedt
2010/7/13 John Reid : > Hi, > > I have some arrays of various shapes in which I need to set any NaNs to > 0. I just ran across numpy.nan_to_num(): >>> a = numpy.log(-1) >>> b = numpy.log([-1, 1]) >>> a nan >>> b array([ NaN, 0.]) >>> numpy.nan_to_num(a) 0.0 >>> numpy.nan_to_num(b) array([ 0.,

Re: [Numpy-discussion] Difference between shape=() and shape=(1,)

2010-07-14 Thread John Reid
Benjamin Root wrote: > On Tue, Jul 13, 2010 at 12:45 PM, Kurt Smith > wrote: > > On Tue, Jul 13, 2010 at 11:54 AM, John Reid > mailto:j.r...@mail.cryst.bbk.ac.uk>> > wrote: > > Hi, > > > > I have some arrays of various shapes in which I need t

Re: [Numpy-discussion] Difference between shape=() and shape=(1,)

2010-07-13 Thread Benjamin Root
On Tue, Jul 13, 2010 at 12:45 PM, Kurt Smith wrote: > On Tue, Jul 13, 2010 at 11:54 AM, John Reid > wrote: > > Hi, > > > > I have some arrays of various shapes in which I need to set any NaNs to > > 0. I have been doing the following: > > > > a[numpy.where(numpy.isnan(a)] = 0. > > > > > > > > as

Re: [Numpy-discussion] Difference between shape=() and shape=(1,)

2010-07-13 Thread Keith Goodman
On Tue, Jul 13, 2010 at 10:36 AM, Pauli Virtanen wrote: > ti, 2010-07-13 kello 10:06 -0700, Keith Goodman kirjoitti: >> No need to use where. You can just do a[np.isnan(a)] = 0. But you do >> have to watch out for 0d arrays, can't index into those. > > You can, but the index must be appropriate: >

Re: [Numpy-discussion] Difference between shape=() and shape=(1,)

2010-07-13 Thread Keith Goodman
On Tue, Jul 13, 2010 at 10:45 AM, Kurt Smith wrote: > You could make use of np.atleast_1d, and then everything would be > canonicalized: > > In [33]: a = np.array(np.nan) > > In [34]: a > Out[34]: array(nan) > > In [35]: a1d = np.atleast_1d(a) > > In [36]: a1d > Out[36]: array([ NaN]) > > In [37

Re: [Numpy-discussion] Difference between shape=() and shape=(1,)

2010-07-13 Thread Kurt Smith
On Tue, Jul 13, 2010 at 11:54 AM, John Reid wrote: > Hi, > > I have some arrays of various shapes in which I need to set any NaNs to > 0. I have been doing the following: > > a[numpy.where(numpy.isnan(a)] = 0. > > > > as you can see here: > > In [20]: a=numpy.ones(2) > > In [21]: a[1]=numpy.log(-1

Re: [Numpy-discussion] Difference between shape=() and shape=(1,)

2010-07-13 Thread Pauli Virtanen
ti, 2010-07-13 kello 10:06 -0700, Keith Goodman kirjoitti: > No need to use where. You can just do a[np.isnan(a)] = 0. But you do > have to watch out for 0d arrays, can't index into those. You can, but the index must be appropriate: >>> x = np.array(4) >>> x[()] = 3 >>> x array(3) _

Re: [Numpy-discussion] Difference between shape=() and shape=(1,)

2010-07-13 Thread Keith Goodman
On Tue, Jul 13, 2010 at 9:54 AM, John Reid wrote: > Hi, > > I have some arrays of various shapes in which I need to set any NaNs to > 0. I have been doing the following: > > a[numpy.where(numpy.isnan(a)] = 0. > > as you can see here: > > In [20]: a=numpy.ones(2) > > In [21]: a[1]=numpy.log(-1) > >

[Numpy-discussion] Difference between shape=() and shape=(1,)

2010-07-13 Thread John Reid
Hi, I have some arrays of various shapes in which I need to set any NaNs to 0. I have been doing the following: a[numpy.where(numpy.isnan(a)] = 0. as you can see here: In [20]: a=numpy.ones(2) In [21]: a[1]=numpy.log(-1) In [22]: a Out[22]: array([ 1., NaN]) In [23]: a[numpy.where(numpy