Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- p1 = np.array((1,2))
- p2 = p1
- def f(p1,p2):
- try:
- x = 1/(np.linalg.norm(p1-p2)**2)
- except ZeroDivisionError:
- x = 0
- return x
- f(p1,p2)
- import numpy as np
- p1 = np.array((1,2))
- p2 = p1
- def f(p1,p2):
- with np.errstate(divide='raise'):
- try:
- x = 1/(np.linalg.norm(p1-p2)**2)
- except FloatingPointError:
- x = 0
- return x
- f(p1,p2))
- import numpy as np
- p1 = np.array((1,2))
- p2 = p1
- def f(p1,p2):
- old_settings = np.seterr(divide='raise')
- try:
- x = 1/(np.linalg.norm(p1-p2)**2)
- except FloatingPointError:
- x = 0
- np.seterr(**old_settings)
- return x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement