0
0
NumPydata~5 mins

np.linalg.norm() for vector norms in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does np.linalg.norm() compute when applied to a vector?

np.linalg.norm() calculates the length or size of a vector, also called the vector's norm.

Click to reveal answer
beginner
How do you calculate the Euclidean norm (length) of a vector v using np.linalg.norm()?

Use np.linalg.norm(v). This gives the straight-line distance from the origin to the point represented by v.

Click to reveal answer
intermediate
What parameter do you use in np.linalg.norm() to calculate the Manhattan norm (sum of absolute values)?

Set ord=1 in np.linalg.norm() to get the Manhattan norm, which sums the absolute values of vector elements.

Click to reveal answer
intermediate
What does np.linalg.norm(v, ord=np.inf) compute?

It computes the maximum absolute value among the elements of vector v, called the infinity norm.

Click to reveal answer
advanced
If you want to calculate the squared Euclidean norm of a vector v efficiently, what is a good approach?

Calculate np.dot(v, v) instead of np.linalg.norm(v)**2 to avoid the square root and save computation.

Click to reveal answer
What is the default norm calculated by np.linalg.norm() when applied to a vector?
AEuclidean norm (L2 norm)
BManhattan norm (L1 norm)
CInfinity norm
DSquared Euclidean norm
Which ord value in np.linalg.norm() gives the Manhattan norm?
Anp.inf
B0
C2
D1
What does np.linalg.norm(v, ord=np.inf) return?
ASum of vector elements
BMaximum absolute value
CMinimum absolute value
DEuclidean norm
How can you compute the squared Euclidean norm of a vector v efficiently?
Anp.linalg.norm(v)**2
Bnp.sum(v)
Cnp.dot(v, v)
Dnp.linalg.norm(v, ord=2)
What will np.linalg.norm([3, 4]) return?
A5
B25
C12
D7
Explain how to use np.linalg.norm() to calculate different types of vector norms and give examples.
Think about the 'ord' parameter and what each norm means.
You got /4 concepts.
    Describe why and how you might compute the squared Euclidean norm of a vector without using np.linalg.norm().
    Consider the math behind Euclidean norm and dot product.
    You got /3 concepts.