python中的np.exp,python中scipy / numpy中的exp溢出?

What does the following error:

Warning: overflow encountered in exp

in scipy/numpy using Python generally mean? I'm computing a ratio in log form, i.e. log(a) + log(b) and then taking the exponent of the result, using exp, and using a sum with logsumexp, as follows:

c = log(a) + log(b)

c = c - logsumexp(c)

some values in the array b are intentionally set to 0. Their log will be -Inf.

What could be the cause of this warning? thanks.

解决方案

In your case, it means that b is very small somewhere in your array, and you're getting a number (a/b or exp(log(a) - log(b))) that is too large for whatever dtype (float32, float64, etc) the array you're using to store the output is.

Numpy can be configured to

Ignore these sorts of errors,

Print the error, but not raise a warning to stop the execution (the default)

Log the error,

Raise a warning

Raise an error

Call a user-defined function

See numpy.seterr to control how it handles having under/overflows, etc in floating point arrays.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值