Re: [Numpy-discussion] mean of two or more arrays while ignoring a specific value

2009-07-14 Thread David Warde-Farley
On 14-Jul-09, at 3:33 PM, Greg Fiske wrote: > Dear list, > > > > I'm learning to work with numpy arrays. Can somebody explain how to > get the > average of two separate arrays while ignoring a user defined value > in one > array? > > > > For example: > a = numpy.array([1,5,4,99]) >

Re: [Numpy-discussion] mean of two or more arrays while ignoring a specific value

2009-07-14 Thread Robert Kern
On Tue, Jul 14, 2009 at 14:42, Chris Colbert wrote: > for your particular case: > a = np.array([1, 5, 4, 99], 'f') b = np.array([3, 7, 2, 8], 'f') c = b.copy() d = a!=99 c[d] = (a[d] + b[d])/2. c > array([ 2.,  6.,  3.,  8.], dtype=float32) A more general answer

Re: [Numpy-discussion] mean of two or more arrays while ignoring a specific value

2009-07-14 Thread Angus McMorland
2009/7/14 Greg Fiske : > Dear list, > > I’m learning to work with numpy arrays.  Can somebody explain how to get the > average of two separate arrays while ignoring a user defined value in one > array? > > For example: > a = numpy.array([1,5,4,99]) b = numpy.array([3,7,2,8]) > > Ignoring th

Re: [Numpy-discussion] mean of two or more arrays while ignoring a specific value

2009-07-14 Thread Chris Colbert
for your particular case: >>> a = np.array([1, 5, 4, 99], 'f') >>> b = np.array([3, 7, 2, 8], 'f') >>> c = b.copy() >>> d = a!=99 >>> c[d] = (a[d] + b[d])/2. >>> c array([ 2., 6., 3., 8.], dtype=float32) >>> On Tue, Jul 14, 2009 at 3:36 PM, Chris Colbert wrote: > index with a boolean array? >

Re: [Numpy-discussion] mean of two or more arrays while ignoring a specific value

2009-07-14 Thread Chris Colbert
index with a boolean array? >>> import numpy as np >>> a = np.array([3, 3, 3, 4, 4, 4]) >>> a array([3, 3, 3, 4, 4, 4]) >>> np.average(a) 3.5 >>> b = a != 3 >>> b array([False, False, False, True, True, True], dtype=bool) >>> np.average(a[b]) 4.0 >>> On Tue, Jul 14, 2009 at 3:33 PM, Greg Fisk

[Numpy-discussion] mean of two or more arrays while ignoring a specific value

2009-07-14 Thread Greg Fiske
Dear list, I'm learning to work with numpy arrays. Can somebody explain how to get the average of two separate arrays while ignoring a user defined value in one array? For example: >>>a = numpy.array([1,5,4,99]) >>>b = numpy.array([3,7,2,8]) Ignoring the value 99, the result should b

Re: [Numpy-discussion] performance matrix multiplication vs. matlab

2009-07-14 Thread Keith Goodman
On Sun, Jun 7, 2009 at 2:52 AM, Gabriel Beckers wrote: > OK, perhaps I drank that beer too soon... > > Now, numpy.test() hangs at: > > test_pinv (test_defmatrix.TestProperties) ... > > So perhaps something is wrong with ATLAS, even though the building went > fine, and "make check" and "make ptcheck

[Numpy-discussion] np.isfinite on structured arrays

2009-07-14 Thread Pierre GM
All, Consider the following code: >>> a = np.array(zip(np.arange(3)),dtype=[('a',float)]) >>> np.isfinite(a) NotImplemented That is, when the input is a structured array, np.isfinite returns an object of type NotImplementedType. I would have expected it to raise a NotImplementedError excepti

Re: [Numpy-discussion] Integer Overflow?

2009-07-14 Thread Jed Ludlow
Dave wrote: > I got stung when taking an ordinary python integer to the power of a numpy > integer - the result wasn't what I was expecting (see below)! From the results below, it seems to be okay if the base is a long. Note the type of the returned result in each case. Does it seem inconsiste

[Numpy-discussion] Integer Overflow?

2009-07-14 Thread Dave
I got stung when taking an ordinary python integer to the power of a numpy integer - the result wasn't what I was expecting (see below)! Taking a wild guess I expect this is due to integer overflow (since it doesn't show up with int64). When working with an int32 type one has to be aware of such i