Instagram
youtube
Facebook
Twitter

Compute the Eigenvalues of a NumPy Array

    Compute the Eigenvalues of a NumPy Array
     
     Short Description of the Program:

     This program calculates the eigenvalues of a square matrix using NumPy’s np.linalg.eig() function.
     
      Explanation:

  • np.array()
    Creates a square matrix (same number of rows and columns).

     

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

     

    1. Eigenvalues
       

    2. Eigenvectors (not used in this case, so we use _ to ignore it)
       

  • print()
    Displays the original matrix and the computed eigenvalues.

     

Program:

import numpy as np

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

                  [1, 1]])

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

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

print("\nEigenvalues of the Array:", eigenvalues)