0
0
NumPydata~20 mins

np.linalg.eig() for eigenvalues in NumPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
đŸŽ–ī¸
Eigen Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of eigenvalues from a 2x2 matrix?
Given the matrix [[4, 2], [1, 3]], what are the eigenvalues computed by np.linalg.eig()?
NumPy
import numpy as np
matrix = np.array([[4, 2], [1, 3]])
eigenvalues, _ = np.linalg.eig(matrix)
print(eigenvalues)
A[5.0, 2.0]
B[3.0, 4.0]
C[6.0, 1.0]
D[4.0, 3.0]
Attempts:
2 left
💡 Hint
Recall eigenvalues satisfy the characteristic equation det(A - ÎģI) = 0.
❓ data_output
intermediate
1:00remaining
Number of eigenvalues returned by np.linalg.eig()
If you apply np.linalg.eig() to a 3x3 matrix, how many eigenvalues will be returned?
NumPy
import numpy as np
matrix = np.eye(3)
eigenvalues, _ = np.linalg.eig(matrix)
print(len(eigenvalues))
A6
B1
C3
D9
Attempts:
2 left
💡 Hint
The number of eigenvalues equals the size of the matrix dimension.
🔧 Debug
advanced
2:00remaining
Identify the error in eigenvalue calculation code
What error will this code raise?
import numpy as np
matrix = np.array([1, 2, 3, 4])
eigenvalues, eigenvectors = np.linalg.eig(matrix)
NumPy
import numpy as np
matrix = np.array([1, 2, 3, 4])
eigenvalues, eigenvectors = np.linalg.eig(matrix)
ALinAlgError: Last 2 dimensions of the array must be square
BTypeError: 'numpy.ndarray' object is not callable
CValueError: too many values to unpack (expected 2)
DNo error, outputs eigenvalues and eigenvectors
Attempts:
2 left
💡 Hint
Check the shape of the input matrix for eig().
🧠 Conceptual
advanced
1:30remaining
What does np.linalg.eig() return?
Which of the following best describes the outputs of np.linalg.eig() when applied to a square matrix?
AOnly the eigenvectors as a matrix
BA tuple with eigenvalues array and eigenvectors matrix
COnly the eigenvalues as a list
DA single array combining eigenvalues and eigenvectors
Attempts:
2 left
💡 Hint
Think about what information is needed to fully describe eigen decomposition.
🚀 Application
expert
2:30remaining
Find the eigenvalue with the largest magnitude
Given the matrix [[0, -1], [1, 0]], which eigenvalue has the largest absolute value?
NumPy
import numpy as np
matrix = np.array([[0, -1], [1, 0]])
eigenvalues, _ = np.linalg.eig(matrix)
max_abs = max(abs(eigenvalues))
print(max_abs)
A2.0
B1.0
C0.0
DComplex number with magnitude 1.0
Attempts:
2 left
💡 Hint
Consider eigenvalues of rotation matrices and their magnitudes.