I have two numpy ndarrays of the same shape (15081, 56724, 3, 3). What I want to do is as follows:
Say we have a cross section of the first array, array1[1, 1, :, :], looks like this:
[[120, 110, 220],
[ 85, 99, 72],
[197, 80, 75]]
I want to convert it to a boolean in a way that the max of each row is True and the rest is False. In the whole array, this corresponds to axis=3. So the array looks like this after conversion:
[[False, False, True],
[False, True, False],
[ True, False, False]]
Now I want to filter the other array, array2, using this boolean array to have something that looks like below. I only want to keeping those values of array2 that correspond to True in array1 and set the rest to zero.
[[ 0, 0, 65],
[ 0, 179, 0],
[125, 0, 0]]
I can do this using a loop but it takes an age (even more).
I expect something like numpy.where(array1.is_max(axis=3), True, False), but there is no function like is_max in python, besides this way the axis 3 is collapsed and I cannot filter array2 using array1.