[SciPy-user] slice question

Robert Kern robert.kern@gmail....
Wed Feb 11 17:34:35 CST 2009


On Wed, Feb 11, 2009 at 17:31, Karl Young <karl.young@ucsf.edu> wrote:
>
> Sorry for the dumb question but I did search quite a bit before
> realizing it would only take a couple of keystrokes from an Illuminati
> to dispel my ignorance.
>
> I want to slice an array as:
>
> A[a:b,c:d,e:f,...]
>
> starting with two 1d arrays containing the lower and upper slice limits:
>
> B = [a,c,e,...] and C = [b,d,f,...]
>
> and I'd like to write a general expression for this given A,B,C (i.e.
> not specify the dimension) but I can't figure out how to turn B and C
> into  a:b,c:d,e:f,... re indexing A - any thoughts ? Thanks

A[tuple([slice(b,c) for b,c in zip(B,C)])]

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the SciPy-user mailing list