SVD on the original matrix
produces same results in both Python and MATLAB (ignoring the signs). However, when I center the matrix, the last column of V
differs between Python and MATLAB.
MATLAB Code:
[~,~,pc_nc]=svd(matrix,'econ');
matrixCenter=matrix-repmat(mean(matrix),size(matrix,1),1);
[~,~,pc_c]=svd(matrixCenter,'econ');
Python Code:
_, _, pc_nc = np.linalg.svd(matrix, full_matrices=False)
pc_nc = pc_nc.transpose()
matrixCenter = matrix - np.matlib.repmat(np.mean(matrix, 0), np.size(matrix, 0), 1)
_, _, pc_c = np.linalg.svd(matrixCenter, full_matrices=False)
pc_c = pc_c.transpose()
pc_nc
in both Python and MATLAB is same. pc_c
differs on the last column.
The matrix
can be found here: https://docs.google.com/spreadsheets/d/1bLrz0EFCuon7YXS_IY1J9Va6u0MSASYZlLJVQ4TN95A/edit#gid=0
I tried using scipy.linalg.svd()
but to no avail. How can I get the same results across all the columns on the centered matrix? Please help.