Python &引用;属性错误:';非类型'';写'&引用&&引用;运行时警告:溢出双“U标量”在while循环期间接收
我用一个while循环来获得放射性元素的向后衰变曲线Python &引用;属性错误:';非类型'';写'&引用&&引用;运行时警告:溢出双“U标量”在while循环期间接收,python,python-3.x,while-loop,runtime-error,attributeerror,Python,Python 3.x,While Loop,Runtime Error,Attributeerror,我用一个while循环来获得放射性元素的向后衰变曲线 import numpy as np import csv lmbd=np.log(2)/12.43 year=list(range(-48050,2012)) f=0 decay=[] decay.append(0.45) # concentration of sample during year of sampling while f<len(year): # Creating the backwards decay cu
import numpy as np
import csv
lmbd=np.log(2)/12.43
year=list(range(-48050,2012))
f=0
decay=[]
decay.append(0.45) # concentration of sample during year of sampling
while f<len(year): # Creating the backwards decay curve sample
p=decay[f]
x=p/np.exp(-lmbd)
decay.append(x)
f=f+1
print(decay)
文件“C:\Python32\lib\idlelib\PyShell.py”,第59行,在idle\u showwarning中
file.write(warnings.formatwarning(消息、类别、文件名、
AttributeError:“非类型”对象没有属性“写入”
但是,如果我将len(year)
替换为50
,则循环运行平稳。如果我将len(year)
替换为50062
(len(year)的值),我仍然会得到错误
lmbd
值较小,所以值不会变得太大)- 如果我在
中运行脚本(根据用户建议),我会得到cmd
错误中遇到溢出运行时警告:在双标量x=p/np.exp(-lmbd)
- 另外,如果我在脚本中添加了
(根据eruksun的建议),我也会在IDLE中得到正确的错误(我正在使用)import sys,idlelib.PyShell;idlelib.PyShell.warning_stream=sys.stderr
- 脚本现在可以运行到完成,但是衰减列表的末尾有大量的
值,这些值将在下一点中处理inf
- 我尝试将
语句替换为while
while fI刚刚复制并粘贴了您的代码,它对我来说运行良好。我得到了
。为了避免溢出,我在运行时警告:双标量中遇到了溢出
处停止,方法是更改循环条件:inf
while fI get
中遇到的erflow这不是您的问题中的错误,而是希望显示错误的环境“Python Shell”中的错误。如果您在没有Python Shell的情况下执行此操作,您可能会看到原始错误。如果您使用“-n”(无子进程)空闲运行如果没有用于运行时警告:ov在double_scalars x=p/np.exp(-lmbd)
的控制台/终端,您可以尝试以下操作来查看警告:stderr
。在这种情况下import sys,idlelib.PyShell;idlelib.PyShell.warning\u stream=sys.stderr
是一个sys.stderr
。PyShell.PseudoOutputFile
x=p/np.exp(-lmbd)
import numpy as np import csv import sys, idlelib.PyShell; idlelib.PyShell.warning_stream = sys.stderr lmbd=np.log(2)/12.43 year=list(range(-48050,2012)) f=0 decay=[] decay.append(0.45)# concentration of sample during year of sampling while f<len(year): # Creating the backwards decay equation for each sample p=decay[f] x=p/np.exp(-lmbd) if x==np.inf: break decay.append(x) f=f+1 print(decay) print("end")