RuntimeWarning: divide by zero encountered in log

前端 未结 5 1144
无人共我
无人共我 2020-12-02 01:25

I am using numpy.log10 to calculate the log of an array of probability values. There are some zeros in the array, and I am trying to get around it using

resu         


        
5条回答
  •  生来不讨喜
    2020-12-02 02:21

    numpy.log10(prob) calculates the base 10 logarithm for all elements of prob, even the ones that aren't selected by the where. If you want, you can fill the zeros of prob with 10**-10 or some dummy value before taking the logarithm to get rid of the problem. (Make sure you don't compute prob > 0.0000000001 with dummy values, though.)

提交回复
热议问题