The first 2 examples make use of this rule.
In the 2nd example, the 2d array, it shows explicitly what [0, 3, 1, 2, 0]
produces
# [row1 + row2 + row3] 0:3
# [row4] 3
# [row2] 1:2
# [row3] 2
# [row1 + row2 + row3 + row4] 0:end
In the first example, this rule is partly hidden by the [::2] indexing.
Without that:
In [183]: np.add.reduceat(np.arange(8),[0,4, 1,5, 2,6, 3,7])
Out[183]: array([ 6, 4, 10, 5, 14, 6, 18, 7])
There's [0:4]sum, [4], [1,5]sum, [5], [2:6]sum, [6], [3:7]sum, 7
Selecting just the odd results, we get 4 range sums:
In [184]: _[::2]
Out[184]: array([ 6, 10, 14, 18])
In [187]: [np.arange(0,4).sum(),np.arange(1,5).sum(),np.arange(2,6).sum()]
Out[187]: [6, 10, 14]