I have a 3D numpy array A
of shape 10 x 5 x 3. I also have a vector B
of length 3 (length of last axis of A
). I want to compare each A[:,:,i]
against B[i]
where i = 0:2
and replace all values A[:,:,i] > B[i]
with B[i]
.
Is there a way to achieve this without a for loop.
Edit: I tried the argmax
across i = 0:2
using a for loop
python replace values in 2d numpy array