Search code examples
pythonnumpyinverse

Solve linear equation in python XA = B


A linear equation XA = B, we know the 'X = B * inv(A)'. where A, B, X are all matrix.

in the matlab it can be solve:

X = B / A

it avoid doing inverse a matrix which is fast. is there any equal form in python using numpy?


Solution

  • Use numpy linalg.inv function:

    import numpy as np
    x = np.matmul(b, np.linalg.inv(a))