Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does numpy.linalg.norm ord=2 work?

Tags:

python

numpy

I am new to Numpy. I couldn't understand the use of ord=2 in numpy.linalg.norm. For example, what is the difference between:

np.linalg.norm(np.array([[-4, -3, -2],
                         [-1,  0,  1],
                         [ 2,  3,  4]]))

and

np.linalg.norm(np.array([[-4, -3, -2],
                         [-1,  0,  1],
                         [ 2,  3,  4]]),2)

In Numpy documentation, it is given that ord =2 means 2-norm (largest sing. value). I couldn't understand what is meant by largest singular value. Could you explain?

like image 267
Muthuraja Palaniappan Avatar asked Mar 23 '26 01:03

Muthuraja Palaniappan


1 Answers

They are referring to the so called operator norm. Your operand is 2D and interpreted as the matrix representation of a linear operator. The operator norm tells you how much longer a vector can become when the operator is applied. The 2 refers to the underlying vector norm. The singular value definition happens to be equivalent.

As for the difference, the default is not the operator norm but the Frobenius norm which is the Euclidean norm if you interpret the matrix as a vector in nxm - space. Looking at examples (the easiest being the identity matrix) it is clear that the Frobenius and operator norms are different.

like image 79
Paul Panzer Avatar answered Mar 24 '26 15:03

Paul Panzer