import math x = math.inf if math.isinf(x): print(f'math: ({x}) is infinity') y = -math.inf if math.isinf(y): print(f'math: ({y})is negative infinity') print() import numpy as np x = np.inf if np.isinf(x): print(f'np:({x}) is infinity') y = -np.inf if np.isinf(y): print(f'np: ({y}) is negative infinity')