Is there a convenient way to split an array such that regardless of the number of elements in each section, the range of values it contains is the same?

Say we have data in range (0, 100). Let the size of the array be 1000. The first 500 elements are all in (0, 20), 300 elements in (20, 40) and so on. I'd like to manipulate values in the subsections split by 20, 40, 60 and 80.

The data could look something like this:

1st div: 0, 0, 0, ... 17, 18

2nd div: 22, 22, 24, ... 37, 39

3rd div: 40, 41, 41, ... 55, 59

4th div: 65, 68, 73, 76, 76

5th div: 93, 96

It's very easy to split an array in equal size sections by the section size. But I'm plotting a trend line using some simple averaging, and the amount of data in each section varies. I know the split points.

It could be made with np.where with a condition like arr > border1 taking only the first element, combining and then splitting, but that seems like a long-ish way of doing things.

Any pointers would be greatly appreciated. I can't be the only one with this problem. Also, if another library does this kind of thing, I'd certainly be open to using it.