tron24

matDiff

Mar 24th, 2021 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. import numpy as np
  2.  
  3. eps = 1e-9
  4.  
  5.  
  6. def diff(a, b):
  7.     if a.shape != b.shape:
  8.         raise Exception("Incompatible Matrices!")
  9.     c = abs(a - b)
  10.     return c.max() > eps
  11.  
  12.  
  13. if __name__ == "__main__":
  14.     a = [[4, 3, 2], [1, 9, 8]]
  15.     a = np.mat(a)
  16.     b = [[12, 34, 19], [-9, 0, 1]]
  17.     b = np.mat(b)
  18.  
  19.     if diff(a, b):
  20.         print("OK!")
  21.     else:
  22.         print("NOT OK!")
  23.  
Add Comment
Please, Sign In to add comment