Instagram
youtube
Facebook
Twitter

Compute the Eigenvectors of a NumPy Array

Compute the Eigenvectors of a NumPy Array

Short Description of the Program:
This program computes the eigenvectors (and eigenvalues) of a square NumPy array using the np.linalg.eig() function.

Explanation:

  • np.array()
    Creates a 2×2 square matrix, which is necessary to compute eigenvectors.

     
  • np.linalg.eig(array)
    Returns two values:

     
    1. eigenvalues: the characteristic roots
       
    2. eigenvectors: the corresponding direction vectors
       
  • print()
    Displays the matrix, its eigenvalues, and eigenvectors.

     

Program:

import numpy as np

array = np.array([[4, -2],

                  [1, 1]])

eigenvalues, eigenvectors = np.linalg.eig(array)

print("Original Array:\n", array)

print("\nEigenvalues:\n", eigenvalues)

print("\nEigenvectors:\n", eigenvectors)