[Numpy-discussion] puzzle: generate index with many ranges

Raik Gruenberg raik.gruenberg@crg...
Fri Jan 30 11:47:16 CST 2009


Hi there,

perhaps someone has a bright idea for this one:

I want to concatenate ranges of numbers into a single array (for indexing). So I
have generated an array "a" with starting positions, for example:

a = [4, 0, 11]

I have an array b with stop positions:

b = [11, 4, 15]

and I would like to generate an index array that takes 4..11, then 0..4, then
11..15.

In reality, a and b have 10000+ elements and the arrays to be "sliced" are very
large so I want to avoid any for loops etc. Any idea how this could be done? I
thought some combination of *repeat* and adding of *arange* should do the trick
but just cannot nail it down.

Thanks in advance for any hints!

Greetings,
Raik




More information about the Numpy-discussion mailing list