Stuck in the convolutional-neural-networks Week 1 assignment pool_backward

I’m stuck in the last function, I’ve done all others, but got error when implementing the pool_backward with mode ‘max’, here is my code

Moderator Edit: Solution Code Removed.

and I got wrong answer

dA_prev1[1,1] = [[ 0. 0. ]
[10.11330283 -0.49726956]
[ 0. 0. ]]

I spent couple hours to locate, but still don’t know what’s wrong with the code. Can anyone help? Thanks in advance.

Your code when mode == "max" is wrong.
Given that:

# Set dA_prev to be dA_prev + (the mask multiplied by the correct entry of dA) (≈1 line)

Your dA entry is not correct. It should take the current height and width, not the current slice.

Thank you so much to point it out, it works now.