0
0
SciPydata~10 mins

Eigenvalues and eigenvectors (eig) in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the function that calculates eigenvalues and eigenvectors.

SciPy
from scipy.linalg import [1]

matrix = [[2, 0], [0, 3]]
values, vectors = [1](matrix)
Drag options to blanks, or click blank then click option'
Aeig
Binv
Cdet
Dsolve
Attempts:
3 left
💡 Hint
Common Mistakes
Using functions like inv or det instead of eig.
Not importing the function before using it.
2fill in blank
medium

Complete the code to create a 2x2 matrix for eigenvalue calculation.

SciPy
import numpy as np

matrix = np.array([1])
values, vectors = eig(matrix)
Drag options to blanks, or click blank then click option'
A[[1, 2], [3, 4]]
B[1, 2, 3, 4]
C[[1, 2, 3], [4, 5, 6]]
D[[1, 2], [3]]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a 1D list instead of a 2D array.
Creating matrices with inconsistent row lengths.
3fill in blank
hard

Fix the error in the code to correctly compute eigenvalues and eigenvectors.

SciPy
from scipy.linalg import eig

matrix = [[4, 1], [2, 3]]
values, vectors = eig([1])
Drag options to blanks, or click blank then click option'
Amatrix.tolist()
B[4, 1, 2, 3]
Cmatrix
Dnp.array(matrix)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a flat list instead of a 2D matrix.
Using undefined variables or wrong data types.
4fill in blank
hard

Fill both blanks to create a dictionary of eigenvalues and their corresponding eigenvectors.

SciPy
values, vectors = eig(matrix)
eigen_dict = {values[[1]]: vectors[:, [2]] for i in range(len(values))}
Drag options to blanks, or click blank then click option'
Ai
B0
C1
Dlen(values)
Attempts:
3 left
💡 Hint
Common Mistakes
Using fixed indices instead of the loop variable.
Mixing up row and column indexing for vectors.
5fill in blank
hard

Fill all three blanks to compute eigenvalues, eigenvectors, and print the first eigenvalue and its vector.

SciPy
from scipy.linalg import [1]
import numpy as np

matrix = np.array([[5, 4], [1, 2]])
values, vectors = [2](matrix)
print('First eigenvalue:', values[[3]])
print('First eigenvector:', vectors[:, 0])
Drag options to blanks, or click blank then click option'
Aeig
Beigvals
C0
Attempts:
3 left
💡 Hint
Common Mistakes
Using eigvals which returns only eigenvalues, not vectors.
Using wrong index for the first eigenvalue.