I have a Numpy array of shape (4320,8640)
. I would like to have an array of shape (2160,4320)
.
You\'ll notice that each cell of the new array m
When the window fits exactly into the array, reshaping to more dimensions and collapsing the extra dimensions with np.sum
is sort of the canonical way of doing this with numpy:
>>> a = np.random.rand(4320,8640)
>>> a.shape
(4320, 8640)
>>> a_small = a.reshape(2160, 2, 4320, 2).sum(axis=(1, 3))
>>> a_small.shape
(2160, 4320)
>>> np.allclose(a_small[100, 203], a[200:202, 406:408].sum())
True