0

I have two arrays A and B which are both (always) the same length. For example:

A = array([ 0, 26, 48, 70, 94, 119]) B = array([ 1, 30, 50, 71, 94, 123])

I'm struggling to find a way in which I could get the range between the pairs in one list. The outcome should look something like this:

C = array([0,1,26,27,28,29,30,48,49,50,70,71,94,119,120,121,122,123])

I tried doing:

for i in A:
   for k in B:
      print(range(i,k))

which results in a mess of ranges.

Any helpers out there?

Samuel
  • 1

2 Answers2

0

From notation, I guess your arrays are np.array, so you can do:

C = np.concatenate([np.arange(a,b) for a,b in zip(A,B+1)])

Output:

array([  0,   1,  26,  27,  28,  29,  30,  48,  49,  50,  70,  71,  94,
       119, 120, 121, 122, 123])
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
0

I think you should just be able to find the range by selecting the first value of the first array [0] and the last value of the second array [-1]:

 print(range(A[0],B[-1])
Oliver Moore
  • 317
  • 1
  • 12