I have the following array (numbers are placeholders for illustration):
arr = np.array([[1, 1, 1, 2, 2, 2, 3, 3, 3, 4 ,4, 4 ],
[1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4 ],
[1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4 ],
[5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8 ],
[5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8 ],
[5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8 ],
[9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12],
[9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12],
[9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12],
[13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16],
[13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16],
[13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16]])
I would like to reduce the dimensions in a way that every 9 elements (3x3 area) having the same numer here would be summed up. So the 12*12 array should become a 4x4 array.
I was looking here for other answers and have found something for a 1D array I adapted. Hoewever, it is not working as expected:
result = np.sum(arr.reshape(-1,3), axis=1)
result = np.sum(result .reshape(3,-1), axis=0)
What is the correct was to achieve the desrired result?