Chris
Chris

Reputation: 21

A numpy.arange style function with array inputs

I have numpy arrays of start indices and end indices from which I'd like to construct a flattened array of ranges.

e.g. with inputs

s = np.array([1,2,3])
e = np.array([4,5,10])

and output

array([1,2,3,2,3,4,3,4,5,6,7,8,9])

any way to do this efficiently?

Upvotes: 2

Views: 663

Answers (1)

tkerwin
tkerwin

Reputation: 9759

How about just

np.concatenate([np.arange(x, y) for x, y in zip(s, e)])

Upvotes: 1

Related Questions