Raik Gruenberg wrote:
Jim Vickroy wrote:
Raik Gruenberg wrote:
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.
Does this help? Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> a = [4, 0, 11]
 >>> b = [11, 4, 15]
 >>> zip(a,b)
[(4, 11), (0, 4), (11, 15)]
 >>>

Mhm, I got this far. But how do I get from here to a single index array

[ 4, 5, 6, ... 10, 0, 1, 2, 3, 11, 12, 13, 14 ] ?

not sure I understand your goal ... is this what you want:
>>> [range(i,j) for i,j in zip(a,b)]
[[4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3], [11, 12, 13, 14]]
>>>
Greetings
Raik



Apologies if I'm stating the obvious.

-- jv
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


_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion




_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to