I am a naive numpy user, need your help for the following problem: I want to replace some elements of a multidimensional array which are less than a second array by a third array; e.g.:
x = np.arange(16).reshape((2, 8))
# x = np.array([[ 0, 1, 2, 3, 4, 5, 6, 7],
# [ 8, 9, 10, 11, 12, 13, 14, 15]])
And
y = np.array([[2], [13]])
# y = np.array([[ 2], [13]])
Now, find out where x is greater than y, and if there is at least one True in x > y array, count these instances, create another array (z) and replace x in these elements with z:
x > y
# = [[False, False, False, True, True, True, True, True],
# [False, False, False, False, False, False, True, True]]
In this case 5 elements of x (x[:,3:]) should be replaced, so we create a (5, 2) array:
z = np.array([[20,21],[22,23],[24,25],[26,27],[28,29]])
The result I want is
x == np.array([[ 0, 1, 2, 20, 22, 24, 26, 28],
[ 8, 9, 10, 21, 23, 25, 27, 29]])