donkon
donkon

Reputation: 919

Normalize matrix l2 norm

Normalize matrix A to get matrix B, where each column vector of B has unit L2-norm.

I don't know what this means. Do I do this?

Take sum of col and sqrt.

[1 0       
 1 1]  --> [1.4 1]

or Make each column have l2-norm of 1.

[1 0       
 1 1]   
--v         
[0.7 0   
0.7 1]

Upvotes: 2

Views: 4391

Answers (1)

6502
6502

Reputation: 114579

The meaning is that you should replace each column vector with its corresponding normalized versor.

For example (Python)

m = [[1, 0],
     [1, 1]]

rows, cols = len(m), len(m[0])
for col in range(cols):
    length = sum(m[row][col]**2 for row in range(rows)) ** 0.5
    for row in range(rows):
        m[row][col] /= length

changes m to

[[0.7071067811865475, 0.0],
 [0.7071067811865475, 1.0]]

Upvotes: 2

Related Questions