如何解决生成多个列表和绘图的 while 循环会产生内存错误
我有以下代码,我想在散点图中根据迭代次数或太阳能输入绘制温度。
我不断收到内存错误,我认为这是由于此代码创建的列表的大小造成的。有什么方法可以将输出存储在其他地方或分解此循环,使输出不会那么大?我目前使用的是 python 3 64 位。
import numpy as np
import matplotlib.pyplot as plt
#define constants
LRange = [1290,1310] #W/m2
Episilon = 1 #no units
Sigma = 5.67E-08 #Wm-2K-4
#L,albedo,nIters = input("").split()
#L,nIters = [float(L),float(albedo),int(nIters) ]
L = 1250
albedo = 0.15
nIters = 1
Ice_Lat_m = 1.5
Ice_lat_c = -322.5
Alb_m = -0.01
Alb_c = 2.8
plottype = "iterDown" #"L","iterUp","iterDown"
x = []
y = []
while L < LRange[1]+1:
for iter in range(nIters):
T = L * ( 1- albedo) / 4 * Sigma
T = T ** (0.25)
albedo = Alb_m * T +Alb_c
albedo = min(albedo,0.65)
albedo = max(albedo,0.15)
lat_ice = Ice_Lat_m * T + Ice_lat_c
lat_ice = min(lat_ice,90)
lat_ice = max(lat_ice,0)
# if plottype is "iter" or plottype is "iterup":
#x.append(iter)
# y.append(T)
# if plottype is "iter" or plottype is "iterup":
# x.append(np.nan)
#y.append(np.nan)
# if plottype is "L":
# x.append(L)
# x.append(T)
L = L + 10
while L > LRange[0]-1:
for iter in range(nIters):
T = L * ( 1- albedo) / 4 * Sigma
T = T ** (0.25)
albedo = Alb_m * T +Alb_c
albedo = min(albedo,0)
#if plottype is "iter" or plottype is "iterdown":
#x.append(iter)
#y.append(T)
# if plottype is "iter" or plottype is "iterdown":
# x.append(np.nan)
y.append(np.nan)
#if plottype is "L":
#x.append(L)
#x.append(T)
L = L + 10
plt.plot(x,y)
plt.show()
print(T,albedo)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。