In: Computer Science
Print the mean and the first 10 eigenvector images and plot the first 100 eigenvalues using python.
# install numpy using command : [pip3 install numpy] or [pip
install numpy]
# install matplotlib using command : [pip3 install matplotlib] or
[pip install matplotlib]
import numpy as np
from matplotlib import pyplot as plt
def perform_op(data):
"""data matrix should be a square matrix with size greate or equal
to 100"""
if data.shape[0] >= 100 and data.shape[0]==data.shape[1]:
eig_values, norm_eigen_vec = np.linalg.eig(data)
mean = data.mean()
print("Mean", mean)
for i in range(10):
print("Eigen vector ", i+1, ":")
print(norm_eigen_vec[:, i])
plt.plot(range(100), eig_values[:100])
plt.show()
# size of data should be greater than 100
data = np.random.randint(low=0, high=100, size=(150, 150))
perform_op(data)