I have a 3D numpy array
dark = np.array(dark_ref.load())
dark.shape
(100, 384, 249)
I have a list of indices for the second and third dimension
l, r, b = np.where(dark > 9000)
len(r)
1799
len(b)
1799
and I have written this function to replace the values at indices r and b with an average of the adjacent values
def flatten_bad_band(A, x, y): # x is 3d array, y is bad coords
testarr = A.copy()
for a in range(A.shape[0]):
for i in range(A.shape[1]):
for j in range((A.shape[2])):
testarr[a, x[i], y[j]] = (testarr[a, x[i+1], y[j]] + testarr[a, x[i-1], y[j]]) /2
return testarr
test = flatten_bad_band(dark, r, b)
This seems to work, but it is slow...., and I will need to use this on much larger arrays. Is there a better way to do this? I am new to python, numpy and coding!