0
0
NumPydata~5 mins

np.linalg.inv() for matrix inverse in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does np.linalg.inv() do in NumPy?

np.linalg.inv() calculates the inverse of a square matrix. The inverse matrix, when multiplied by the original, gives the identity matrix.

Click to reveal answer
beginner
What kind of matrix can np.linalg.inv() invert?

Only square matrices (same number of rows and columns) that are non-singular (have a non-zero determinant) can be inverted using np.linalg.inv().

Click to reveal answer
intermediate
What happens if you try to invert a singular matrix with np.linalg.inv()?

NumPy will raise a LinAlgError because singular matrices do not have an inverse.

Click to reveal answer
beginner
How can you verify that a matrix A and its inverse A_inv are correct?

Multiply A by A_inv. The result should be the identity matrix, which has 1s on the diagonal and 0s elsewhere.

Click to reveal answer
beginner
Write a simple example to compute the inverse of a 2x2 matrix using np.linalg.inv().
<pre>import numpy as np
A = np.array([[4, 7], [2, 6]])
A_inv = np.linalg.inv(A)
print(A_inv)</pre>
Click to reveal answer
What type of matrix can np.linalg.inv() invert?
AOnly singular matrices
BAny rectangular matrix
CSquare and non-singular matrices
DOnly diagonal matrices
What error does np.linalg.inv() raise if the matrix is singular?
AValueError
BLinAlgError
CTypeError
DIndexError
What is the result of multiplying a matrix by its inverse?
AZero matrix
BTranspose matrix
CDiagonal matrix
DIdentity matrix
Which NumPy module contains the inv() function?
Anumpy.linalg
Bnumpy.random
Cnumpy.fft
Dnumpy.core
What shape must a matrix have to be invertible?
ASquare (same rows and columns)
BRectangular with more rows than columns
CRectangular with more columns than rows
DAny shape
Explain in your own words what np.linalg.inv() does and when you can use it.
Think about what an inverse matrix means in real life.
You got /3 concepts.
    Describe how you would check if a matrix inverse calculation was successful using NumPy.
    What is the identity matrix?
    You got /3 concepts.