Replace -inf with zero value Replace -inf with zero value python python

Replace -inf with zero value


There is:

from numpy import infx[x == -inf] = 0


Perhaps even easier and more flexible to use numpy.nan_to_num:

numpy.nan_to_num(x, neginf=0) Out[1]: array([ 0.        ,  0.        , 37.49668579])