Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-03-17 Thread Pauli Virtanen
Tue, 03 Mar 2009 19:26:38 -0600, Robert Kern wrote: > On Tue, Mar 3, 2009 at 03:11, Stéfan van der Walt > wrote: [clip: ix_(...,:,...)] > No, you're right. It doesn't work. The only way to make it work seems to be to define a special shaped slice object that indexing understands... I wonder if t

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-03-03 Thread Robert Kern
On Tue, Mar 3, 2009 at 03:11, Stéfan van der Walt wrote: > Hi Robert > > 2009/2/27 Robert Kern : >>> a[ix_([2,3,6],range(a.shape[1]),[3,2])] >>> >>> If anyone knows a better way? >> >> One could probably make ix_() take slice objects, too, to generate the >> correct arange() in the appropriate pla

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-03-03 Thread Stéfan van der Walt
Hi Robert 2009/2/27 Robert Kern : >> a[ix_([2,3,6],range(a.shape[1]),[3,2])] >> >> If anyone knows a better way? > > One could probably make ix_() take slice objects, too, to generate the > correct arange() in the appropriate place. I was wondering how one would implement this, since the ix_ func

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-03-02 Thread Robert Kern
On Mon, Mar 2, 2009 at 13:10, David Warde-Farley wrote: > On 2-Mar-09, at 12:25 PM, Robert Kern wrote: > >> a[[2,3,6], ...][..., [3,2]] >> >> You're doing fancy indexing, so there are copies both times. > > D'oh! > > So I guess the only way to avoid the second copy is to do what Jon > initially su

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-03-02 Thread David Warde-Farley
On 2-Mar-09, at 12:25 PM, Robert Kern wrote: > a[[2,3,6], ...][..., [3,2]] > > You're doing fancy indexing, so there are copies both times. D'oh! So I guess the only way to avoid the second copy is to do what Jon initially suggested, i.e. a[ix_([2,3,6],range(a.shape[1]),[3,2])] ? I suppose xr

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-03-02 Thread Robert Kern
On Mon, Mar 2, 2009 at 04:19, David Warde-Farley wrote: > On 28-Feb-09, at 12:27 PM, Jonathan Taylor wrote: > >> This does seem like the only way to write this nicely.  Unfortunately, >> I think this may be wasteful memory wise (in contrast to what the >> obvious matlab code would do) as it constr

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-03-02 Thread David Warde-Farley
On 28-Feb-09, at 12:27 PM, Jonathan Taylor wrote: > This does seem like the only way to write this nicely. Unfortunately, > I think this may be wasteful memory wise (in contrast to what the > obvious matlab code would do) as it constructs an array with the whole > first index intact at first. Tr

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-02-28 Thread Jonathan Taylor
Hi Dave. This does seem like the only way to write this nicely. Unfortunately, I think this may be wasteful memory wise (in contrast to what the obvious matlab code would do) as it constructs an array with the whole first index intact at first. I think I will use it anyways though as I find the

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-02-27 Thread David Warde-Farley
On 27-Feb-09, at 3:35 PM, David Warde-Farley wrote: > > a[[2,3,6],:,:][:,:,[3,2]] should do what you want. Slightly more elegantly (I always forget about this syntax): a[[2,3,6], ...][..., [3,2]] David ___ Numpy-discussion mailing list Numpy-discussio

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-02-27 Thread Robert Kern
On Thu, Feb 26, 2009 at 21:00, Jonathan Taylor wrote: > Am I right to assume that there is no way elegant way to interact with > slices.  i.e. Is there anyway to get > > a[ix_([2,3,6],:,[3,2])] > > to work?  So that the dimension is completely specified?  Or perhaps > the only way to do this is vi

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-02-27 Thread David Warde-Farley
Hey Jon, On 26-Feb-09, at 10:00 PM, Jonathan Taylor wrote: > Am I right to assume that there is no way elegant way to interact with > slices. i.e. Is there anyway to get > > a[ix_([2,3,6],:,[3,2])] > > to work? So that the dimension is completely specified? Or perhaps > the only way to do thi

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2009-02-26 Thread Jonathan Taylor
Am I right to assume that there is no way elegant way to interact with slices. i.e. Is there anyway to get a[ix_([2,3,6],:,[3,2])] to work? So that the dimension is completely specified? Or perhaps the only way to do this is via a[ix_([2,3,6],range(a.shape[1]),[3,2])] If anyone knows a bette

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2007-09-11 Thread Travis E. Oliphant
Timothy Hochberg wrote: > > > On 9/11/07, *Robert Kern* <[EMAIL PROTECTED] > > wrote: > > Mike Ressler wrote: > > The following seems to be a wart: is it expected? > > > > Set up a 10x10 array and some indexing arrays: > > > > a=arange(100) > >

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2007-09-11 Thread Mike Ressler
Thanks, Robert, for the quick response. On 9/11/07, Robert Kern <[EMAIL PROTECTED]> wrote: > There are operations you can express with this form that you couldn't if the > behavior that you expected were the case whereas you can get the result you > want > relatively straightforwardly. > > In [6]

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2007-09-11 Thread Timothy Hochberg
On 9/11/07, Robert Kern <[EMAIL PROTECTED]> wrote: > > Mike Ressler wrote: > > The following seems to be a wart: is it expected? > > > > Set up a 10x10 array and some indexing arrays: > > > > a=arange(100) > > a.shape=(10,10) > > q=array([0,2,4,6,8]) > > r=array([0,5]) > > > > Suppose I want to ext

Re: [Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2007-09-11 Thread Robert Kern
Mike Ressler wrote: > The following seems to be a wart: is it expected? > > Set up a 10x10 array and some indexing arrays: > > a=arange(100) > a.shape=(10,10) > q=array([0,2,4,6,8]) > r=array([0,5]) > > Suppose I want to extract only the "even" numbered rows from a - then > > print a[q,:] > >

[Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

2007-09-11 Thread Mike Ressler
The following seems to be a wart: is it expected? Set up a 10x10 array and some indexing arrays: a=arange(100) a.shape=(10,10) q=array([0,2,4,6,8]) r=array([0,5]) Suppose I want to extract only the "even" numbered rows from a - then print a[q,:] Every fifth column: print a[:,r] Only the