Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-146

Center Rows

Problem

Center each row of data by subtracting that row's mean.

Return the centered data as a list of rows of floats; every centered row sums to 0.

Hint

This is the row-wise analogue of centering columns.

Test cases

case 1
in: [[[1,2,3],[4,5,6]]]
expected: [[-1,0,1],[-1,0,1]]
case 2
in: [[[1,1],[0,2]]]
expected: [[0,0],[-1,1]]
case 3
in: [[[5]]]
expected: [[0]]
case 4
in: [[[1,3],[2,4]]]
expected: [[-1,1],[-1,1]]
Starter codePython
def center_rows(data):
    # Your code here
    pass

4 test cases · run your code against them in the editor