spyder
win10
python3
from numpy.linalg import inv,qr
generate a random matrix of 5 to 5
X = np.random.randn(5,5)
first find the transpose of the matrix (.T), and then find the dot product (.dot)
mat = X.T.dot(X)
find the inverse of the matrix
inv(mat)
get the unit matrix
mat.dot(inv(mat))
use QR decomposition to assign values to QMagi R
respectively.q,r = qr(mat)
get orthogonal matrix
orthogonal matrix, and the product of matrix and its transpose matrix is E
q
get the upper triangular matrix
r
In order to understand the QR factorization, I multiply the orthogonal matrix and its inverted matrix. Theoretically, I should get the unit matrix E1, but my output is not a matrix with diagonal 1 and other elements 0? May I ask what is wrong and what is the problem?
E1 = q*(q.T)
E1