I have two numpy arrays A and B and a mask mask of booleans (True/False), all of identical dimensions. I want to replace the elements in A with those of B where the corresponding element of mask is True; where the corresponding element of mask is False I want to retain the original element of A. How can I do this?
Example:
# Input
A = np.arange(9).reshape(3,3)
B = A*10
mask = np.array([[True, True, False], [False, True, False], [False, False, True]])
# Output
desired_output = np.array([[0, 10, 2], [3, 40, 5], [6, 7, 80]])