Re: [Numpy-discussion] 2 greatest values, in a 3-d array, along one axis

2012-08-03 Thread eat
Hi, On Fri, Aug 3, 2012 at 7:02 PM, Angus McMorland wrote: > On 3 August 2012 11:18, Jim Vickroy wrote: > >> Hello everyone, >> >> I'm trying to determine the 2 greatest values, in a 3-d array, along one >> axis. >> >> Here is an approach: >> >> # ---

Re: [Numpy-discussion] 2 greatest values, in a 3-d array, along one axis

2012-08-03 Thread Jim Vickroy
Thanks for each of the improved solutions. The one using argsort took a little while for me to understand. I have a long way to go to fully utilize fancy indexing! -- jv On 8/3/2012 10:02 AM, Angus McMorland wrote: On 3 August 2012 11:18, Jim Vickroy > wrote:

Re: [Numpy-discussion] 2 greatest values, in a 3-d array, along one axis

2012-08-03 Thread Angus McMorland
On 3 August 2012 11:18, Jim Vickroy wrote: > Hello everyone, > > I'm trying to determine the 2 greatest values, in a 3-d array, along one > axis. > > Here is an approach: > > # -- > # procedure to determine greatest 2 values for 3rd dimension of

Re: [Numpy-discussion] 2 greatest values, in a 3-d array, along one axis

2012-08-03 Thread Daπid
Here is the 3D implementation: http://pastebin.com/ERVLWhbS I was only able to do it using a double nested loop, but I am sure someone more clever than me can do a slicing trick to overcome it. Otherwise, I hope this is fast enough for your purpose. David. On Fri, Aug 3, 2012 at 4:41 PM, Daπid

Re: [Numpy-discussion] 2 greatest values, in a 3-d array, along one axis

2012-08-03 Thread Daπid
Here goes a 1D simple implementation. It shouldn't be difficult to generalize to more dimensions, as all the functions support axis argument: >>> a=np.array([1, 2, 3, 5, 2]) >>> a.max() # This is the maximum value 5 >>> mask=np.zeros_like(a) >>> mask[np.argmax(a)]=1 >>> a=np.ma.masked_array(a, ma

[Numpy-discussion] 2 greatest values, in a 3-d array, along one axis

2012-08-03 Thread Jim Vickroy
Hello everyone, I'm trying to determine the 2 greatest values, in a 3-d array, along one axis. Here is an approach: # -- # procedure to determine greatest 2 values for 3rd dimension of 3-d array ... import numpy, numpy.ma xcnt, ycnt, zcnt =