如何在二维数组中取四个相邻项(2*2)的平均值?我的输入是:
[[1,1,1,1],
[1,1,0,0],
[0,0,1,1],
[0,0,0,0]]
应该得到的结果是:
[[1, 0.5],
[0, 0.5]]
numpy.mean(x.reshape(-1, 4), 1)将数组展平并稍微以错误的顺序平均四个项目。
其他信息
例如,该数组是通过以下方法生成的:
n = 10
l = 100
A = np.zeros((l, l))
points = l*np.random.random((2, n**2))
A[(points[0]).astype(np.int), (points[1]).astype(np.int)] = 1
A = ndimage.gaussian_filter(A, sigma=l/(4.*n))
2 x 2
块的平均值吗? - Andras Deak -- Слава Україні