There appears to be more than one statistic you wish to collect about each block. Using toblocks
(below) you can apply various computations to the last axis of blocks
to obtain the desired statistics:
import numpy as np
import scipy.stats as stats
def toblocks(arr, nrows, ncols):
h, w = arr.shape
blocks = (arr.reshape(h // nrows, nrows, -1, ncols)
.swapaxes(1, 2)
.reshape(h // nrows, w // ncols, ncols * nrows))
return blocks
data=np.array([
[0,0,1,1,1,1],
[1,0,0,1,1,1],
[1,0,1,1,0,1],
[1,1,0,1,0,0]])
blocks = toblocks(data, 2, 2)
vals, counts = stats.mode(blocks, axis=-1)
vals = vals.squeeze()
print(vals)
# [[ 0. 1. 1.]
# [ 1. 1. 0.]]