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.
- How to create a vector in Python using NumPy
- Divide each row by a vector element using NumPy
- Python | Numpy numpy.matrix.any()
- Python | Numpy numpy.matrix.all()
- Python | Numpy numpy.matrix.A()
- Python | Numpy numpy.matrix.T()
- Python | Numpy numpy.matrix.H()
- NumPy | Vector Multiplication
- How to get the magnitude of a vector in NumPy?
- Find the number of rows and columns of a given matrix using NumPy
- How to inverse a matrix using NumPy
- Flatten a Matrix in Python using NumPy
- Compute the condition number of a given matrix using NumPy
- Compute the inverse of a matrix using NumPy
- How to Calculate the determinant of a matrix using NumPy?
- Calculate the QR decomposition of a given matrix using NumPy
- Python | Numpy numpy.resize()
- Python | Numpy numpy.transpose()
- Python | Numpy numpy.ndarray.__lt__()
- Python | Numpy numpy.ndarray.__gt__()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.