Is there a way where I can calculate the inverse of a mxn non-square matrix using numpy? Since using la.inv(S)
seems to give me an error of ValueError: expected square matrix
You are probably looking for np.linalg.pinv
.
Alaboration: pinv (psaudu-inverse) computes the Moore–Penrose pseudo inverse of a matrix using its SVD, when the matrix is non invertible ( thanks https://stackoverflow.com/users/774575/mins )
To calculate the non square matrix mxn, We can use np.linalg.pinv(S), here s is the data you want to pass.
For square matrix we use np.linalg.inv(S), The inverse of a matrix is such that if it is multiplied by the original matrix, it results in identity matrix.
note: np is numpy
We can also use np.linalg.inv(S) for non square matrix but in order to not get any error you need to slice the data S.
For more details on np.linalg.pinv : https://numpy.org/doc/stable/reference/generated/numpy.linalg.pinv.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With