# Demonstration of using numpy to compute eigenvalues and eigenvalues # CMP 464/788 Spring 2017 # Megan Owen import numpy as np # create a 2x2 matrix m = np.array([[1,2],[3,4]]) print("Matrix is:",m) evals, evects = np.linalg.eig(m) print("Eigenvalues are: ",evals) print("Corresponding eigenvectors are:",evects) det = np.linalg.det(m) print("Determinant is:",det) identity = np.array([[1,0],[0,1]]) # 2x2 matrix multiplication is done using the dot() method in numpy. # Using * performs coordinate-wise multiplication between the two arrays. m_matmult_id = np.dot(m,identity) print("Matrix multiplication of m with the identity matrix:",m_matmult_id) m_coordmult_id = m*identity print("Coordindate-wise multiplication of m with the identity matrix:",m_coordmult_id)