Sum Over the Last Two Axes

easynumpy_reductions

Implement sum_last_two(A).

Given an array A with at least 2 dimensions, return the array obtained by summing over its last two axes (result shape A.shape[:-2]). No for/while loops.

Constraints
  • no scipy, sklearn
  • no for/while loops

Your solution

Edit sum_last_two and run the real pytest suite in your browser — no install required. Your code is saved locally.

⌘/Ctrl + ↵

Loading the Python runtime (first run only)…

Hints

Hint 1

Pass a tuple of axes to sum: A.sum(axis=(-2, -1)).