The numpy.matrix method is syntactically the simplest. However, numpy.array is the most practical.
import numpy as np
A = np.matrix([[3,6,-5],
[1,-3,2],
[5,-1,4]])
b = np.matrix([[12],
[-2],
[10]])
x = A**(-1) * b
print(x)
#output:
#[[1.75]
# [1.75]
# [0.75]]
A = np.array([[3,6,-5],
[1,-3,2],
[5,-1,4]])
b = np.array([[12],
[-2],
[10]])
x = np.linalg.inv(A).dot(b)
print(x)
#output:
#[[1.75]
# [1.75]
# [0.75]]
Last Updated on 2022-12-13 by gantovnik
Recent Comments