Premium problem135. Max-Pool Forward with Stride

Medium Locked

Given X of shape (N, C, H, W), pool height ph, pool width pw and stride, return the (N, C, OH, OW) array of per-window maxima:

  • OH = (H - ph) // stride + 1
  • no padding
  • drop incomplete trailing windows

Input

X =
[[[[ 0.  1.  2.  3.]
   [ 4.  5.  6.  7.]
   [ 8.  9. 10. 11.]
   [12. 13. 14. 15.]]

  [[16. 17. 18. 19.]
   [20. 21. 22. 23.]
   [24. 25. 26. 27.]
   [28. 29. 30. 31.]]]]
ph = 2
pw = 2
stride = 2

Output

[[[[ 5.  7.]
   [13. 15.]]

  [[21. 23.]
   [29. 31.]]]]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)