Premium problem87. Block-Sum (4×4 blocks)

Hard Locked

Given a matrix Z whose dimensions are multiples of k, return the matrix of block sums:

  • partition Z into non-overlapping k×k blocks
  • the result has shape (Z.shape[0] // k, Z.shape[1] // k)

Input

Z = np.ones((16, 16))
k = 4

Output

[[16. 16. 16. 16.]
 [16. 16. 16. 16.]
 [16. 16. 16. 16.]
 [16. 16. 16. 16.]]

Premium problem

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

Implement solve(...)