numpy - Ignore divide by 0 warning in python -
i have function statistic issues: import numpy np scipy.special import gamma gamma def foo(xdata): ... return x1 * ( ( #r numpy vector ( ((r - x2)/beta) ** (x3 -1) ) * ( np.exp( - ((r - x2) / x4) ) ) / ( x4 * gamma(x3)) ).real ) sometimes shell following warning: runtimewarning: divide 0 encountered in... i use numpy isinf function correct results of function in other files need do. not need warning. there way ignore message? in other words, not want shell print message. i not want disable python warning, one. you can disable warning numpy.seterr . put before possible division zero: np.seterr(divide='ignore') that'll disable 0 division warnings globally. if want disable them little bit, can use numpy.errstate in with clause: with np.errstate(divide='ignore'): # code here for 0 zero division (undetermined, results