OKPEDIA PYTHON VECTOR

How to calculate eigenvalues in Python

To calculate the eigenvalues in Python, use linalg.eigvals() function of the NumPy module.

linalg.eigvals(m)

The parameter m is a matrix.

The linalg.eigvals function returns the eigenvalues.

What are the eigenvalues? They are scalar numbers that allow to calculate the eigenvectors of a matrix.

Example

Import the numpy module into the python interpreter.

import numpy as np

Defining an array using the Array() function

matrix = np.array([[3,1],[1,1]])

It is a square matrix

$$ matrix = \begin{pmatrix} 3 & 1 \\ 1 & 1 \end{pmatrix} $$

Calculate the eigenvalues of the matrix using the eigvals(matrix) function.

np.linalg.eigvals(matrix)

The function outputs the eigenvalues of the matrix.

array([3.41421356, 0.58578644])

In this case the matrix has two eigenvalues.

https://how.okpedia.org/en/python/how-to-calculate-eigenvalues-with-python


Report us an error or send a suggestion to improve this page


Python


FacebookTwitterLinkedinLinkedin