Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Implementing Eigenvectors & Eigenvalues in Python | Linear Algebra Foundations
Mathematics for Data Science

bookImplementing Eigenvectors & Eigenvalues in Python

Eigenvalues and eigenvectors are fundamental in linear algebra and arise in many data science applications — from PCA and dimensionality reduction to understanding systems dynamics and optimization.
They allow us to understand how matrices stretch or rotate vectors in space.

Defining the Matrix

# Define matrix A (square matrix)
A = np.array([[2, 1],
              [1, 2]])

This matrix represents a symmetric 2×22×2 system. We're going to analyze its properties through decomposition.

Computing Eigenvalues and Eigenvectors

12345678910111213
import numpy as np from numpy.linalg import eig # Define matrix A (square matrix) A = np.array([[2, 1], [1, 2]]) # Solve for eigenvalues and eigenvectors eigenvalues, eigenvectors = eig(A) # Print eigenvalues and eigenvectors print(eigenvalues) print(eigenvectors)
copy

NumPy's eig() computes the solutions to the equation:

Av=λvA v = \lambda v
  • eigenvalues: a list of scalars $\lambda$ that scale eigenvectors;
  • eigenvectors: columns representing $v$ (directions that don’t change under transformation).

Validating Each Pair (Key Step)

12345678910111213141516
import numpy as np from numpy.linalg import eig # Define matrix A (square matrix) A = np.array([[2, 1], [1, 2]]) # Solve for eigenvalues and eigenvectors eigenvalues, eigenvectors = eig(A) # Verify that A @ v = λ * v for each eigenpair for i in range(len(eigenvalues)): λ = eigenvalues[i] v = eigenvectors[:, i].reshape(-1, 1) print(A @ v) print(λ * v)
copy

This checks if:

Av=λvA v = \lambda v

The two sides should match closely, which confirms correctness. This is how we validate theoretical properties numerically.

1. What does np.linalg.eig(A) return?

2. Which equation defines eigenvectors and eigenvalues?

3. What is the geometric interpretation of an eigenvector?

4. Why do we check Av=λvA v = \lambda v for each pair?

5. What happens if matrix A has complex eigenvalues?

question mark

What does np.linalg.eig(A) return?

Select the correct answer

question mark

Which equation defines eigenvectors and eigenvalues?

Select the correct answer

question mark

What is the geometric interpretation of an eigenvector?

Select the correct answer

question mark

Why do we check Av=λvA v = \lambda v for each pair?

Select the correct answer

question mark

What happens if matrix A has complex eigenvalues?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 12

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Suggested prompts:

Can you explain what eigenvalues and eigenvectors represent in simple terms?

How do I interpret the output of the eigenvalues and eigenvectors in this example?

Can you walk me through the validation step in more detail?

Awesome!

Completion rate improved to 1.89

bookImplementing Eigenvectors & Eigenvalues in Python

Sveip for å vise menyen

Eigenvalues and eigenvectors are fundamental in linear algebra and arise in many data science applications — from PCA and dimensionality reduction to understanding systems dynamics and optimization.
They allow us to understand how matrices stretch or rotate vectors in space.

Defining the Matrix

# Define matrix A (square matrix)
A = np.array([[2, 1],
              [1, 2]])

This matrix represents a symmetric 2×22×2 system. We're going to analyze its properties through decomposition.

Computing Eigenvalues and Eigenvectors

12345678910111213
import numpy as np from numpy.linalg import eig # Define matrix A (square matrix) A = np.array([[2, 1], [1, 2]]) # Solve for eigenvalues and eigenvectors eigenvalues, eigenvectors = eig(A) # Print eigenvalues and eigenvectors print(eigenvalues) print(eigenvectors)
copy

NumPy's eig() computes the solutions to the equation:

Av=λvA v = \lambda v
  • eigenvalues: a list of scalars $\lambda$ that scale eigenvectors;
  • eigenvectors: columns representing $v$ (directions that don’t change under transformation).

Validating Each Pair (Key Step)

12345678910111213141516
import numpy as np from numpy.linalg import eig # Define matrix A (square matrix) A = np.array([[2, 1], [1, 2]]) # Solve for eigenvalues and eigenvectors eigenvalues, eigenvectors = eig(A) # Verify that A @ v = λ * v for each eigenpair for i in range(len(eigenvalues)): λ = eigenvalues[i] v = eigenvectors[:, i].reshape(-1, 1) print(A @ v) print(λ * v)
copy

This checks if:

Av=λvA v = \lambda v

The two sides should match closely, which confirms correctness. This is how we validate theoretical properties numerically.

1. What does np.linalg.eig(A) return?

2. Which equation defines eigenvectors and eigenvalues?

3. What is the geometric interpretation of an eigenvector?

4. Why do we check Av=λvA v = \lambda v for each pair?

5. What happens if matrix A has complex eigenvalues?

question mark

What does np.linalg.eig(A) return?

Select the correct answer

question mark

Which equation defines eigenvectors and eigenvalues?

Select the correct answer

question mark

What is the geometric interpretation of an eigenvector?

Select the correct answer

question mark

Why do we check Av=λvA v = \lambda v for each pair?

Select the correct answer

question mark

What happens if matrix A has complex eigenvalues?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 12
some-alt