import numpy as np
import numpy.linalg as nla
Let's make a random matrix $A$ and consider a vector of ones $x^{*}={\bf 1}$. Let's let $b=A*x^{*}$. Then we know that $x^{*}$ is the solution to $$ Ax^{*} = b $$
A = np.random.rand(10,10)
xstar = np.ones((10,))
b = A.dot(xstar)
Now, solve the problem with Numpy. We'll first print a measure (that we'll go over later).
x = nla.solve(A,b)
print(" Sensitivity of A:", nla.cond(A))
print("maximum difference from x to xstar:", np.max(np.abs(x-xstar)))
for xi in x:
print(repr(xi))
print(A)
Now let's try something. We should get the same thing solving $$ A A x^* = A b $$
Anew = A.dot(A.dot(A.dot(A.dot(A.dot(A.dot(A.dot(A)))))))
bnew = A.dot(A.dot(A.dot(A.dot(A.dot(A.dot(A.dot(b)))))))
x = nla.solve(Anew,bnew)
print(" Sensitivity of A:", nla.cond(Anew))
print("maximum difference from x to xstar:", np.max(np.abs(x-xstar)))
for xi in x:
print(repr(xi))
import numpy as np
a = np.array([0.1], dtype=np.float
a.nbytes