Complete the code to compute eigenvalues of matrix A.
import numpy as np A = np.array([[2, 0], [0, 3]]) eigenvalues, _ = np.linalg.[1](A) print(eigenvalues)
The function np.linalg.eig() returns eigenvalues and eigenvectors of a square matrix.
Complete the code to extract only eigenvalues from the result.
import numpy as np B = np.array([[4, 1], [2, 3]]) eigenvalues, [1] = np.linalg.eig(B) print(eigenvalues)
The second returned value from np.linalg.eig() is the eigenvectors, commonly named eigenvectors.
Fix the error in the code to correctly compute eigenvalues.
import numpy as np C = np.array([[1, 2], [3, 4]]) eigenvalues, _ = np.linalg.[1](C) print(eigenvalues)
eigvals which returns only eigenvalues and causes an unpacking error.eigen or eigenvalues.The function np.linalg.eig() returns both eigenvalues and eigenvectors of a square matrix. We ignore the eigenvectors using _.
Fill both blanks to create a dictionary of eigenvalue to eigenvector mapping.
import numpy as np D = np.array([[5, 4], [1, 2]]) eigenvalues, eigenvectors = np.linalg.eig(D) result = {eigenvalues[[1]]: eigenvectors[:, [2]] for i in range(len(eigenvalues))} print(result)
Use the loop variable i to index eigenvalues and eigenvectors to build the dictionary.
Fill all three blanks to filter eigenvalues greater than 3 and create a dictionary with their eigenvectors.
import numpy as np E = np.array([[6, 2], [2, 3]]) eigenvalues, eigenvectors = np.linalg.eig(E) filtered = {eigenvalues[[1]]: eigenvectors[:, [2]] for [3] in range(len(eigenvalues)) if eigenvalues[[1]] > 3} print(filtered)
Use the same loop variable i to index eigenvalues and eigenvectors and filter eigenvalues greater than 3.