To find a matrix or vector norm we use function
numpy.linalg.norm() of Python library Numpy. This function returns one of the seven matrix norms or one of the infinite vector norms depending upon the value of its parameters.
Syntax: numpy.linalg.norm(x, ord=None, axis=None)
ord: order of norm
axis: None, returns either a vector or a matrix norm and if it is an integer value, it specifies the axis of x along which the vector norm will be computed
Vector norm: 16.881943016134134
The above code computes the vector norm of a vector of dimension (1, 10)
Matrix norm: 9.539392014169456
Here, we get the matrix norm for a matrix of dimension (2, 3)
To compute matrix norm along a particular axis –
Matrix norm along particular axis : [3.74165739 8.77496439]
This code generates a matrix norm and the output is also a matrix of shape (1, 2)
Vector norm: 14.2828568570857 Matrix norm: 14.2828568570857
From the above output, it is clear if we convert a vector into a matrix, or if both have same elements then their norm will be equal too.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.