I would like to replace the values of a 2D numpy array based on a mask from another array. The idea is that values in arr_b should be set to 0.8 in the locations where arr_a value equals 0.4. Both arr_a and arr_b are always going to have the same size. And for the purpose of this toy example, you can assume that arr_a has sevreral values that are 0.4. But the code is not working:
import numpy
arr_a = numpy.random.rand(20,40)
arr_b = numpy.random.rand(20,40)
arr_a[0,1] = 0.4
mask_cntr = numpy.ma.masked_not_equal(arr_a[:], 0.4)
ma_arr = numpy.ma.masked_where(mask_cntr, arr_b)
ma_arr.filled(fill_value = 0.8)
Can someone tell me how to fix this?
np.mamethods?