除了被零除之外,double_scalars中遇到溢出的原因有哪些? [英] What are the causes of overflow encountered in double_scalars besides division by zero?

查看:2990
本文介绍了除了被零除之外,double_scalars中遇到溢出的原因有哪些?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到有关双标量的内容,但部分理解.据我了解,这是Numpy可以计算的范围.这就是为什么大多数问题都集中在被零除的原因(这是一个错误,因为答案将超出范围(无穷大)).

I read about double scalar but just partly understand. From my understanding, it is the range that is available to calculate by Numpy. That's why most questions here focusing on the division by zero (which is an error because the answer will be out of range (infinity)).

但是我不确定我的理解是正确的.另外,我看不到double_scalars中遇到有关RuntimeWarning:overflow的其他原因.什么会导致双标量中发生溢出?

But I am so unsure that my understanding is correct. Also, I can't see other causes about RuntimeWarning:overflow encountered in double_scalars. What can cause overflow encountered in double scalars?

推荐答案

溢出错误表示操作产生的值超出了为相应数据类型定义的范围.对于numpy double,该范围为(-1.79769313486e+308, 1.79769313486e+308).另外,为了进行良好的讨论,请阅读这篇SO帖子.

Overflow error implies that an operation yields a value out of the range defined for the corresponding data type. For numpy double, that range is (-1.79769313486e+308, 1.79769313486e+308). Also, for a good discussion, please read this SO post.

示例:

import numpy as np
np.seterr(all='warn')
print "Range of numpy double:", np.finfo(np.double).min, np.finfo(np.double).max
A = np.array([143],dtype='double')
a=A[-1]
print "At the border:", a**a
B = np.array([144],dtype='double')
b=B[-1]
print "Blowing out of range:", b**b

输出:

Range of numpy double: -1.79769313486e+308 1.79769313486e+308
At the border: 1.6332525973e+308 
Blowing out of range: inf
D:\anaconda\lib\site-packages\ipykernel\__main__.py:9: RuntimeWarning: overflow encountered in double_scalars

这篇关于除了被零除之外,double_scalars中遇到溢出的原因有哪些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆