I have a numpy array with shape:
In: imar.shape
Out: (21, 77, 10000)
I want a binned sum on the last axis, with every bin containing 20 items.
The way I'm doing this now is:
np.sum( imar.reshape([-1,500,20]), axis=2 ).reshape(imar.shape[:2])
It's fast, but seems error-prone if I get the arguments to reshape wrong. Is there a better way to do this?
I've looked at np.digitize,histogram,bincount, and some others, but those are value based; I want sum over a set of ranges.