我刚开始使用python 3语言进行编码,我正在尝试为gram-schmidt修改的QR分解编写代码。我已经成功地使用numpy编写了代码,但是现在我尝试不使用numpy编写新的代码。任何帮助将非常感谢。我的numpy代码如下。
import numpy as np
def gram_schmidt(A):
""" Representation of Gram-Schmidt Process or QR Diagonalization
for an mxn system of linear equations. """
m = np.shape(A)[0]
n = np.shape(A)[1]
Q = np.zeros((m, m))
R = np.zeros((n, n))
for j in xrange(n):
v = A[:,j]
for i in xrange(j):
R[i,j] = Q[:,i].T * A[:,j]
v = v.squeeze() - (R[i,j] * Q[:,i])
R[j,j] = np.linalg.norm(v)
Q[:,j] = (v / R[j,j]).squeeze()
return Q, R