【发布时间】:2014-03-03 19:53:38
【问题描述】:
我正在使用 numpy.log10 来计算概率值数组的对数。数组中有一些零,我正在尝试使用
result = numpy.where(prob > 0.0000000001, numpy.log10(prob), -10)
但是,RuntimeWarning: divide by zero encountered in log10 仍然出现,我确信是这条线引起了警告。
虽然我的问题解决了,但我很困惑为什么这个警告会一次又一次出现?
【问题讨论】:
-
numpy.log10(prob)在评估where之前被评估。 -
请注意,您最终可以将
numpy.seterr与catch_warnings结合使用来更改numpy 除以零的行为。请参阅this 相关问题。