text_plain_output_1.png
import numpy as np

import pandas as pd

import numpy as np
import pandas as pd
M = np.array([[1, 1, 1, 0, 0], [3, 3, 3, 0, 0], [4, 4, 4, 0, 0], [5, 5, 5, 0, 0], [0, 0, 0, 4, 4], [0, 0, 0, 5, 5], [0, 0, 0, 2, 2]])
d = pd.DataFrame(M, index=['Joe', 'Jim', 'John', 'Jack', 'Jill', 'Jenny', 'Jane'], columns=['Matrix', 'Alien', 'Star Wars', 'Casablanca', 'Titanic'])

np.set_printoptions(precision=2)
Sigma = np.zeros((7, 5), dtype=float)
Sigma[:5, :5] = np.diag(S)
print(f'Sigma:\n {Sigma}')
print('Reconstructured data: U * Sigma * Vt')
print(np.dot(U, np.dot(Sigma, Vt)))