Python Reduced Row Echelon Form

				
					import numpy as np
from sympy import Matrix
				
			
				
					# Example 1
A = np.array([
    [2, 4, 3],
    [1, 2, 3],
    [4, 8, 10]
])
				
			
				
					sympy_matrix_pre_rref = Matrix(A)
				
			
				
					matrix_post_rref = sympy_matrix_pre_rref.rref()
				
			
				
					rref_matrix = matrix_post_rref[0]
				
			
				
					numpy_rref_matrix = np.array(rref_matrix, dtype=float)
				
			
				
					print(rref_matrix)
				
			

From REF to RREF

				
					# Example 1
A1 = np.array([
    [1, 2, 3],
    [0, 1, 4],
    [0, 0, 1]
])
				
			
				
					sympy_matrix_pre_rref = Matrix(A1)
				
			
				
					matrix_post_rref = sympy_matrix_pre_rref.rref()
				
			
				
					rref_matrix = matrix_post_rref[0]
				
			
				
					numpy_rref_matrix = np.array(rref_matrix, dtype=float)
				
			
				
					print(rref_matrix)
				
			

Ryan is a Data Scientist at a fintech company, where he focuses on fraud prevention in underwriting and risk. Before that, he worked as a Data Analyst at a tax software company. He holds a degree in Electrical Engineering from UCF.

Leave a Reply

Your email address will not be published. Required fields are marked *