I want to go through an array and find anomalies (specifically, values higher than 100).
I then want the anomalous cell to be replaced by the mean value of the surrounding cells.
Let's say the input is:
[6, 28, 33]
[20, 100, 41]
[87, 3, 39]
I want to change that 100 cell into the integer mean of
6, 28, 33, 20, 41, 87, 3, 39
which is 32
The output should be:
[6, 28, 33]
[20, 32, 41]
[87, 3, 39]
If it matters, my real array is 256*256 cells, and has ~500 values I want to change
Last point!
I know that there would be a problem fixing up the edges, so I don't care whether they are thrown out completely or some clever piece of code can average without them.
Here is my attempt:
import numpy as np
array = np.random.randint(100, size=(256, 256))
for x in array
if x>=100:
x = np.mean(x+1,x-1)
#This is where I got stuck... trying to define the surrounding cells