I do not quite understand why numpy.linalg.solve()
gives the more precise answer, whereas numpy.linalg.inv()
breaks down somewhat, giving (what I believe are) estimates.
For a concrete example, I am solving the equation C^{-1} * d
where C
denotes a matrix, and d
is a vector-array. For the sake of discussion, the dimensions of C
are shape (1000,1000)
and d
is shape (1,1000)
.
numpy.linalg.solve(A, b)
solves the equation A*x=b
for x, i.e. x = A^{-1} * b.
Therefore, I could either solve this equation by
(1)
inverse = numpy.linalg.inv(C)
result = inverse * d
or (2)
numpy.linalg.solve(C, d)
Method (2) gives far more precise results. Why is this?
What exactly is happening such that one "works better" than the other?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…