Grokking Modern System Design Interview for Engineers & Managers
Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.
In NumPy, the np.linalg.norm()
function is used to calculate one of the eight different matrix norms or one of the vector norms.
numpy.linalg.norm(x, ord=None, axis=None, keepdims=False)
x:
This is an input array.ord:
This stands for “order”. The different orders of the norm are given below:order | norm for matrix | norm for vector |
---|---|---|
None | Frobenius norm | 2-norm |
fro | Frobenius norm | – |
nuc | nuclear norm | – |
inf | max(sum(abs(x), axis=1) | max(abs(x)) |
-inf | min(sum(abs(x), axis=1)) | min(abs(x)) |
0 | – | sum(x != 0) |
1 | max(sum(abs(x), axis=0)) | as below |
-1 | min(sum(abs(x), axis=0)) | as below |
2 | 2-norm (largest sing. value) | as below |
-2 | smallest singular value | as below |
other | – | sum(abs(x)**ord)**(1./ord) |
axis:
If the axis
is an integer, then the vector norm is computed for the axis of x
.If the axis is a 2-tuple, the matrix norms of specified matrices are computed. If the axis is None, then either a vector norm (when x is 1-D) or a matrix norm (when x is 2-D) is returned.
keepdims:
It receives a boolean value. If its value is true, then the axes that are normed over are left in the result as dimensions with size one. Otherwise, the axes which are normed over are kept in the result.
from numpy import linalg as LNGimport numpy as np# creating an array using arrange function# -3, -2, -1, 0, 1, 2, 3, 4, 5a = np.arange(9) - 3# converting the array into a matrix of 3x3a = a.reshape((3,3))# Printing matrixprint(a)# computing norm for a matrixprint(LNG.norm(a))# computing vector normsprint(LNG.norm(a, axis=0))
RELATED TAGS
Grokking Modern System Design Interview for Engineers & Managers
Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.