Subtract Each Row's Mean

mediumnumpy_manipulation

Implement row_demean(X).

Given a 2D array X of shape (m, n), return an array of the same shape where the mean of each row has been subtracted from that row. Vectorize it with broadcasting — no for/while loops.

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

Your solution

Edit row_demean 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

Reduce along axis=1 with keepdims=True so the per-row means broadcast back.