简体   繁体   English

指数溢出

[英]Overflow encountered in exponential

I have this piece of code: 我有这段代码:

from __future__ import division
import matplotlib.pyplot as plt
import os
import numpy as np
import copy
import random
import math

A_bb=9.2572264*10**(-45)
E_bb=4.8043478/10**11

x=np.arange(0,20,0.01)

def func(x,T):
    x=np.array(x)
    return A_bb*(10**x)**3/(np.exp(10**x*E_bb/T)-1)
popt,pcov=curve_fit(func,frec, Flux_57442_27165)
print (popt)

Basically I want to fit a blackbody curve to some data points. 基本上,我想将黑体曲线拟合到一些数据点。 But I get this error: 但是我得到这个错误:

overflow encountered in exp w=A_bb*(10**x)**3/(np.exp(10**x*E_bb/T1)-1)

The value of TI expect is of order 10^4. TI Expect的值约为10 ^ 4。 What is the problem and how can I solve it? 有什么问题,我该如何解决?

Python's native int type, from the documentation is only capable of storing integers upto 2^32: 根据文档 ,Python的本机int类型只能存储最大2 ^ 32的整数:

Plain integers (also just called integers) are implemented using long in C, which gives them at least 32 bits of precision 普通整数(也称为整数)是使用C中的long实现的,这使它们至少具有32位精度

To get around this, Python also provides the long datatype: 为了解决这个问题,Python还提供了long数据类型:

Long integers have unlimited precision. 长整数具有无限的精度。

Simply apply long() to T if an overflow is being encountered: 如果遇到溢出,只需将long()应用于T

T = long(T)

and hope that it works. 并希望它能起作用。


If even that fails, I strongly recommend using numpy instead, which has much more powerful datatypes . 如果失败了,我强烈建议您改用numpy ,它具有更强大的数据类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM