Numpy - use arrays as the beginning and end of a range

This is a simplified array of what I have:

a = np.array([ 1, 12, 60, 80, 90, 210])
b = np.array([11, 30, 79, 89, 99, 232])

How can I get a result that uses athe beginning range as well bas the end of the range, which can quickly calculate a list of numbers.

therefore it cwill look like this:

c = np.array([1,2,3,...,11, 12,13,14,...,29,30, 
              60,61,62,...79, ..., 210,211,...,231,232])

Ideally, this will be done in vectorized form (using numpy / pandas), and not in python.

+4
source share
1 answer

To summarize the comments above: One way is to use zip()and np.concatenate().

c = np.concatenate([np.arange(x, y+1) for x, y in zip(a,b)])

HT - @VasilisG. And @ ThomasKühn

+2
source

Source: https://habr.com/ru/post/1692264/


All Articles