SHARE
TWEET

Untitled

a guest Jun 16th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2.  
  3. p1 = np.array((1,2))
  4. p2 = p1
  5.  
  6. def f(p1,p2):
  7.     try:
  8.         x = 1/(np.linalg.norm(p1-p2)**2)
  9.     except ZeroDivisionError:
  10.         x = 0
  11.     return x
  12.  
  13. f(p1,p2)
  14.      
  15. import numpy as np
  16.  
  17. p1 = np.array((1,2))
  18. p2 = p1
  19.  
  20. def f(p1,p2):
  21.     with np.errstate(divide='raise'):
  22.         try:
  23.             x = 1/(np.linalg.norm(p1-p2)**2)
  24.         except FloatingPointError:
  25.             x = 0
  26.         return x
  27.  
  28. f(p1,p2))
  29.      
  30. import numpy as np
  31.  
  32. p1 = np.array((1,2))
  33. p2 = p1
  34.  
  35. def f(p1,p2):
  36.  
  37.     old_settings = np.seterr(divide='raise')
  38.     try:
  39.         x = 1/(np.linalg.norm(p1-p2)**2)
  40.     except FloatingPointError:
  41.         x = 0
  42.     np.seterr(**old_settings)
  43.     return x
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top