In this article, we will discuss how to compute the eigenvalues and right eigenvectors of a given square array using NumPy library.
Example:
Suppose we have a matrix as: [[1,2], [2,3]] Eigenvalue we get from this matrix or square array is: [-0.23606798 4.23606798] Eigenvectors of this matrix are: [[-0.85065081 -0.52573111], [ 0.52573111 -0.85065081]]
To know how they are calculated mathematically see this Calculation of EigenValues and EigenVectors. In the below examples, we have used numpy.linalg.eig() to find eigenvalues and eigenvectors for the given square array.
Syntax: numpy.linalg.eig()
Parameter: An square array.
Return: It will return two values first is eigenvalues and second is eigenvectors.
Example 1:
Python3
# importing numpy library import numpy as np # create numpy 2d-array m = np.array([[1, 2], [2, 3]]) print("Printing the Original square array:\n", m) # finding eigenvalues and eigenvectors w, v = np.linalg.eig(m) # printing eigen values print("Printing the Eigen values of the given square array:\n", w) # printing eigen vectors print("Printing Right eigenvectors of the given square array:\n" v) |
Output:
Printing the Original square array: [[1 2] [2 3]] Printing the Eigen values of the given square array: [-0.23606798 4.23606798] Printing Right eigenvectors of the given square array: [[-0.85065081 -0.52573111] [ 0.52573111 -0.85065081]]
Example 2:
Python3
# importing numpy library import numpy as np # create numpy 2d-array m = np.array([[1, 2, 3], [2, 3, 4], [4, 5, 6]]) print("Printing the Original square array:\n", m) # finding eigenvalues and eigenvectors w, v = np.linalg.eig(m) # printing eigen values print("Printing the Eigen values of the given square array:\n", w) # printing eigen vectors print("Printing Right eigenvectors of the given square array:\n", v) |
Output:
Printing the Original square array: [[1 2 3] [2 3 4] [4 5 6]] Printing the Eigen values of the given square array: [ 1.08309519e+01 -8.30951895e-01 1.01486082e-16] Printing Right eigenvectors of the given square array: [[ 0.34416959 0.72770285 0.40824829] [ 0.49532111 0.27580256 -0.81649658] [ 0.79762415 -0.62799801 0.40824829]]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Connection Between Eigenvectors and Nullspace
- Compute the determinant of a given square array using NumPy in Python
- How to compute natural, base 10, and base 2 logarithm for all elements in a given array using NumPy?
- Compute the factor of a given array by Singular Value Decomposition using NumPy
- Compute the mean, standard deviation, and variance of a given NumPy array
- Compute the outer product of two given vectors using NumPy in Python
- How to compute the cross product of two given vectors using NumPy?
- Compute the condition number of a given matrix using NumPy
- Compute the weighted average of a given NumPy array
- How to compute numerical negative value for all elements in a given NumPy array?
- Compute the natural logarithm of one plus each element in floating-point accuracy Using NumPy
- Compute the inner product of vectors for 1-D arrays using NumPy in Python
- Compute the inner product of vectors for 1-D arrays using NumPy in Python
- Compute the inverse of a matrix using NumPy
- Compute the histogram of a set of data using NumPy in Python
- Compute the covariance matrix of two given NumPy arrays
- Compute pearson product-moment correlation coefficients of two given NumPy arrays
- Compute the Reciprocal for all elements in a NumPy array
- Compute the median of the flattened NumPy array
- Compute the Kronecker product of two mulitdimension NumPy arrays
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

