Skip to content

Commit

Permalink
Changed numpy.transpose(foo) to foo.T
Browse files Browse the repository at this point in the history
  • Loading branch information
drreynolds committed Jan 27, 2021
1 parent bbf1e06 commit 00a0b74
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions LUFactorization/TestLU.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
if (numpy.linalg.norm(U - numpy.triu(U))>tol):
checks_out = False
print(" LUPFactors failure: U is not upper-triangular")
if (numpy.linalg.norm(numpy.transpose(P)@P - numpy.eye(n))>tol):
if (numpy.linalg.norm(P.T@P - numpy.eye(n))>tol):
checks_out = False
print(" LUPFactors failure: P is not a permutation matrix")
if (numpy.linalg.norm(A-numpy.transpose(P)@L@U)>tol):
if (numpy.linalg.norm(A-P.T@L@U)>tol):
checks_out = False
print(" LUPFactors failure: A ~= P^T L U")
if (checks_out):
Expand Down
6 changes: 3 additions & 3 deletions QRFactorization/QRFactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ def QRFactors(A):

# update rows k through m of R
for j in range(n):
utR = 2 * numpy.transpose(u) @ R[k:m, j]
utR = 2 * u.T @ R[k:m, j]
R[k:m, j] -= u*utR

# update rows k through m of Q
for j in range(m):
utQ = 2 * numpy.transpose(u) @ Q[k:m, j]
utQ = 2 * u.T @ Q[k:m, j]
Q[k:m, j] -= u*utQ

# transpose Q before return
Q = numpy.transpose(Q)
Q = Q.T

return [Q, R]

Expand Down
16 changes: 8 additions & 8 deletions QRFactorization/TestQR.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
Q, R = QRFactors(A)

# output results
print(" ||I-Q^TQ|| = ", numpy.linalg.norm(I-numpy.transpose(Q)@Q,2))
print(" ||I-QQ^T|| = ", numpy.linalg.norm(I-Q@numpy.transpose(Q),2))
print(" ||I-Q^TQ|| = ", numpy.linalg.norm(I-Q.T@Q,2))
print(" ||I-QQ^T|| = ", numpy.linalg.norm(I-Q@Q.T,2))
print(" ||A-QR|| = ", numpy.linalg.norm(A-Q@R,2))
print(" ||tril(R,-1)|| = ", numpy.linalg.norm(numpy.tril(R,-1),2))

Expand All @@ -44,8 +44,8 @@
Q, R = QRFactors(A)

# output results
print(" ||I-Q^TQ|| = ", numpy.linalg.norm(I-numpy.transpose(Q)@Q,2))
print(" ||I-QQ^T|| = ", numpy.linalg.norm(I-Q@numpy.transpose(Q),2))
print(" ||I-Q^TQ|| = ", numpy.linalg.norm(I-Q.T@Q,2))
print(" ||I-QQ^T|| = ", numpy.linalg.norm(I-Q@Q.T,2))
print(" ||A-QR|| = ", numpy.linalg.norm(A-Q@R,2))
print(" ||tril(R,-1)|| = ", numpy.linalg.norm(numpy.tril(R,-1),2))

Expand All @@ -63,8 +63,8 @@
Q, R = QRFactors(A)

# output results
print(" ||I-Q^TQ|| = ", numpy.linalg.norm(I-numpy.transpose(Q)@Q,2))
print(" ||I-QQ^T|| = ", numpy.linalg.norm(I-Q@numpy.transpose(Q),2))
print(" ||I-Q^TQ|| = ", numpy.linalg.norm(I-Q.T@Q,2))
print(" ||I-QQ^T|| = ", numpy.linalg.norm(I-Q@Q.T,2))
print(" ||A-QR|| = ", numpy.linalg.norm(A-Q@R,2))
print(" ||tril(R,-1)|| = ", numpy.linalg.norm(numpy.tril(R,-1),2))

Expand All @@ -81,8 +81,8 @@
Q, R = QRFactors(A)

# output results
print(" ||I-Q^TQ|| = ", numpy.linalg.norm(I-numpy.transpose(Q)@Q,2))
print(" ||I-QQ^T|| = ", numpy.linalg.norm(I-Q@numpy.transpose(Q),2))
print(" ||I-Q^TQ|| = ", numpy.linalg.norm(I-Q.T@Q,2))
print(" ||I-QQ^T|| = ", numpy.linalg.norm(I-Q@Q.T,2))
print(" ||A-QR|| = ", numpy.linalg.norm(A-Q@R,2))
print(" ||tril(R,-1)|| = ", numpy.linalg.norm(numpy.tril(R,-1),2))

Expand Down

0 comments on commit 00a0b74

Please sign in to comment.