This is something I've been struggling with for a couple of weeks. The algorithm is the following:
- Select a subarray as an array of rows and columns from a larger array
- Compute the median of the subarray
- Replace cells in subarray with median value
- Move the subarray to the right by its own length
- Repeat to end of array
- Move subarray down by its own height
- Repeat
I've got steps 1 to 3 as follows:
import numpy as np
w1 = np.arange(100).reshape(10,10)
side = 3
patch = w1[0:side, 0:side]
i, j = patch.shape
for j in range(side):
for i in range(side):
patch[i,j] = np.median(patch)
Eventually, I'll be using a 901x877 array from an image but I'm just trying to get a hold of this simple task first. How can I slide the array along and then down with a loop?