SZanlongo
4/3/2015 - 5:04 PM

Simplify Matrix by Averaging Multiple Cells From http://stackoverflow.com/questions/29435842/simplify-matrix-by-averaging-multiple-cells

# You could split your array into blocks with the view_as_blocks function (in scikit image).
# For a 2D array, this returns a 4D array with the blocks ordered row-wise:
import skimage.util as ski
import numpy as np
a = np.arange(16).reshape(4,4) # 4x4 array
print ski.view_as_blocks(a, (2,2))

# Taking the mean along the last two axes returns a 2D array with the mean in each block:
print ski.view_as_blocks(a, (2,2)).mean(axis=(2,3))