I have a numpy array: a = [[1, 999, 3], [-1, 1, 3], [2, 999, 6]]
I want to find every instance of number 999 and replace it with the average of the two neighbouring numbers (999 is always in the middle).
I used the following code to try and make this work: np.where(a == 999, .5 * (a[0] + a[2]), a)
But the output I get appends the value I calculate for the first array: [[1, 2, 3], [-1, 1, 3], [2, 2, 6]] instead of:[[1, 2, 3], [-1, 1, 3], [2, 4, 6]]
How can I fix that?