I need to replace an element of a numpy array subject to the minimum of another numpy array verifying one condition. See the following minimal example:
arr = np.array([0, 1, 2, 3, 4])
label = np.array([0, 0, 1, 1, 2])
cond = (label == 1)
label[cond][np.argmin(arr[cond])] = 3
I would be expecting that label is now
array([0, 0, 3, 1, 2])
instead I am getting
array([0, 0, 1, 1, 2])
This is a consequence of the known fact that numpy arrays are not updated with double slicing.
Anyway, I can't figure out how to rewrite the above code in a simple way. Any hint?