All problems
Normalize Columns L2
Problem
Normalize every column of matrix A to unit L2 length.
If a column is the zero vector, leave it as zeros. Return a list of rows of floats.
Hint
Compute each column norm first, then scale all entries in that column.
Test cases
case 1
in: [[[3,0],[4,0]]]
expected: [[0.6,0],[0.8,0]]
case 2
in: [[[1,0],[0,1]]]
expected: [[1,0],[0,1]]
case 3
in: [[[1,1],[1,1]]]
expected: [[0.7071067811865475,0.7071067811865475],[0.7071067811865475,0.7071067811865475]]
case 4
in: [[[0,0],[0,0]]]
expected: [[0,0],[0,0]]
Starter codePython
def normalize_columns(A):
# Your code here
pass4 test cases · run your code against them in the editor