def block_view(A, block=(3, 3)):
    """Provide a 2D block view to 2D array. No error checking made.
    Therefore meaningful (as implemented) only for blocks strictly
    compatible with the shape of A."""
shape = (A.shape[0] / block[0], A.shape[1] / block[1]) + block
strides = (block[0] * A.strides[0], block[1] * A.strides[1]) + A.strides
return ast(A, shape=shape, strides=strides)
if __name__ == '__main__':
    B = block_view(A).sum(axis=(2, 3))
Суммирование каждого окна 3x3 матрицы M*N в матрицу M/3*N/3 с помощью numpy