Guest User

Untitled

a guest
Nov 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. def compare_floats(f1, f2):
  2.     '''
  3.         compare two floats
  4.     '''
  5.     epsilon = 1e-6
  6.     if(math.fabs(f1 - f2) > epsilon):
  7.         return False
  8.     else:
  9.         return True
  10.  
  11. def matrix_compare(matrixA, matrixB):
  12.     '''
  13.         compare two matrices and returns True or False
  14.     '''
  15.    
  16.     if (matrixA.col_size != matrixB.col_size) or (matrixA.row_size != matrixB.row_size):
  17.         return False
  18.    
  19.     rows = matrixA.row_size
  20.     cols = matrixA.col_size
  21.     # iterate over the matrix
  22.     for row in range(rows):
  23.         for col in range(cols):
  24.             if compare_floats(matrixA[row][col], matrixB[row][col]) == False:
  25.                 return False
  26.    
  27.     return True
Add Comment
Please, Sign In to add comment