Block Sum
mediumnumpy_manipulationImplement block_sum(X, b).
Given a 2D array X of shape (n, n) where n is divisible by b, return
a (n//b, n//b) array whose entry (r, c) is the sum of the non-overlapping
b x b block at block-row r, block-column c. Use reshaping — no
for/while loops.
Constraints
- no scipy, sklearn
- no for/while loops
Your solution
Edit block_sum and run the real pytest suite in your browser — no install required. Your code is saved locally.
Loading the Python runtime (first run only)…
Hints
Hint 1
Reshape (n, n) to (n//b, b, n//b, b) and sum axes 1 and 3.