I've got a 2d array like this:
[[0.77 nan 0.57 0.56 0.86 nan nan nan nan 0.71]
[ nan nan nan nan 0.94 0.53 nan 0.61 0.97 0.86]
[0.86 0.92 nan nan nan 0.94 nan nan nan nan]
[0.71 0.74 0.56 0.83 nan nan nan 0.8 0.85 0.79]
[ nan nan 0.61 0.73 nan 0.61 0.55 nan 0.88 0.8 ]
[ nan nan nan 0.77 0.81 0.59 0.89 nan 0.61 nan]
[ nan 0.67 0.67 0.57 0.56 0.69 nan nan 0.9 nan]
[ nan 0.91 nan 0.62 0.94 nan 0.84 0.75 0.73 0.69]
[0.63 0.59 0.56 0.52 nan nan 0.7 nan 0.87 nan]
[0.76 nan nan nan nan nan 0.78 nan nan 0.83]]
and I want to fill the nan values with the average value of it's surroundings. For example: The nan-value in the 3rd row and the 3rd column should be the average out of 0.92, 0.74, 0.56 and 0.83 (=0.7625).
I tried this with
scipy.ndimage.median_filter(array, size=(3, 3))
but this will lead to a wrong answer. Is there a way to this?