Meine Frage ist es wie ich die Eingabe der Matrix aussieht. Ich habs mit A = [ [0,1,0,1,1], [0,1,0,1,1], [0,1,0,1,1], [0,1,0,1,1], [0,1,0,1,1] ] probiert so geht's nicht. Bzw. weiß ich nicht woher das "shape" kommt.
Code: Alles auswählen
def householder(A):
m = A.shape[0]; n = A.shape[1]; Q = eye(m, n);
QA = A
for j in range(n-1):
a = QA[j:, j]
na = linalg.norm(a)
v = a + sign(a[0].item)*na*eye(m-j,1)
nv2 = linalg.norm(v)**2
Qr = eye(m-j, n-j) - 2.0*dot(v, v.T)/nv2
Qrx = eye(m, n); Qrx[j:, j:] = Qr
Q = dot(Qrx, Q)
QA = dot(Qrx, A)
R = dot(Q, A)
return Q, R