def row_echelon(matlist, K):
 result_matlist = copy.deepcopy(matlist)
 nrow = len(result_matlist)
 for i in range(nrow):
  if ((result_matlist[i][i] != 1) and (result_matlist[i][i] != 0)):
   rowmul(result_matlist, i, (1 / result_matlist[i][i]), K)
  for j in range((i + 1), nrow):
   if (result_matlist[j][i] != 0):
    rowadd(result_matlist, j, i, (- result_matlist[j][i]), K)
 return result_matlist

def row_echelon ( matlist , K ) : result_matlist = copy . deepcopy ( matlist ) nrow = len ( result_matlist ) for i in range ( nrow ) : if ( ( result_matlist [ i ] [ i ] != 1 ) and ( result_matlist [ i ] [ i ] != 0 ) ) : rowmul ( result_matlist , i , ( 1 / result_matlist [ i ] [ i ] ) , K ) for j in range ( ( i + 1 ) , nrow ) : if ( result_matlist [ j ] [ i ] != 0 ) : rowadd ( result_matlist , j , i , ( - result_matlist [ j ] [ i ] ) , K ) return result_matlist
returns the row echelon form of a matrix with diagonal elements reduced to 1 .