Reputation: 103
I am working on a project for my Linear Algebra class. I am stuck with a small problem. I could not find any method for finding the row-echelon matrix form (not reduced) in Python (not MATLAB). Could someone help me out? Thank you.
(I use python3.x)
Upvotes: 3
Views: 4212
Reputation: 356
Bill M's answer is correct. When you find the LU decomposition the U matrix is a correct way of writing M in REF (note that REF is not unique so there are multiple possible ways to write it). To see why, remember that the LU decomposition finds P,L,U such that PLU = M. When L is full rank we can write this as U = (PL)-1M. So (PL)-1 defines the row operations that you have to preform on M to change it into U.
Upvotes: 3
Reputation: 1548
I think scipy.linalg's "lu" can do that:
>>> from scipy.linalg import lu
>>> import numpy as np
>>> M = np.array([[0,3,-6,6,4,-5], [3,-7,8,-5,8,9], [3,-9,12,-9,6,15]])
>>> p,l,u = lu(M)
>>> u
array([[ 3. , -7. , 8. , -5. , 8. , 9. ],
[ 0. , 3. , -6. , 6. , 4. , -5. ],
[ 0. , 0. , 0. , 0. , 0.66666667, 2.66666667]])
>>>
Upvotes: 2