[Matrix-SIG] Creative slicing

Gary Strangman strang@NMR.MGH.Harvard.EDU
Mon, 6 Sep 1999 17:09:06 -0400 (EDT)


Hi all,

I've recently come across a need that someone on this list might be able
to help with.  I'm trying to do the following with good speed using numpy
...

x = lots_o_data
x.shape = (100,40,50)
y = indices_into_data
y.shape = (40,50)   # filled with ints in the 0-99 range

I want z where z.shape=(40,50) and the elements of z are chosen from x
according to the corresponding index in y.  Make sense?  That is, if
y[0,0] = 21 then I want z[0,0] = x[21,0,0], and so on.  take() doesn't
seem capable of this.  Might indices() be combined with take() or
something like that?  Maybe there's something hidden down deep inside
numpy that could do this for me.  I'm looking for a shape-independent
solution (i.e., so I can make my function ufunc-like). 

Or is this just wishful thinking ??? ;-)

Gary Strangman

--------------------------------------------------------------
Gary Strangman, PhD        |  Neural Systems Group
Office: 617-724-0662       |  Massachusetts General Hospital
Home:   401-453-3796       |  13th Street, Bldg 149, Room 9103
strang@nmr.mgh.harvard.edu |  Charlestown, MA  02129
http://www.nmr.mgh.harvard.edu/Neural_Systems_Group/gary/