I have a big data set of floating point numbers. I iterate through them and evaluate np.log(x) for each of them. I get
np.log(x)
RuntimeWarning: divide b
you could do:
def safe_ln(x): #returns: ln(x) but replaces -inf with 0 try: l = np.log(x) except RunTimeWarning: l = 0 return l