Python Forum
Memory error in python 2.7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Memory error in python 2.7
#1

Here's my errpr message, last time I got this I had a logic error in a loop, but I can't find anything like that in this. Does anyone spot my problem?
Error:
runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Main Program.py', wdir='C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction') C:\Python27\lib\site-packages\IPython\core\formatters.py:239: FormatterWarning: Exception in image/png formatter: Could not allocate memory for image FormatterWarning, <matplotlib.figure.Figure at 0x2309ef0> Traceback (most recent call last): File "<ipython-input-28-225e42a16155>", line 1, in <module> runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Main Program.py', wdir='C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction') File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile execfile(filename, namespace) File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc) File "C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Main Program.py", line 100, in <module> ax.plot(x, yFunction(veganGrowth, initialPopOmni, popGrowthFactor), 'p-', lw=1, alpha=0.6, label='Major Graph') File "C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Main Program.py", line 62, in yFunction y = initialPop - totFunctions*y MemoryError
Here's the code it's based on.
import numpy as np
from scipy.stats import lognorm
import matplotlib.pyplot as plt
from math import exp
fig, ax = plt.subplots(1, 1)

initialPop = int(326300000)
initialPopOmni = 315532100
popGrowthFactor = 0.007


def runLognormal(start, current, mean, cumImpact, peakFactor):
    scale = exp(mean)
    return lognorm.pdf(current, peakFactor, start, scale)*cumImpact
    
def runLinear(start, stop, slope):
    numQRun = start-stop
    y=[]
    time = start
    while time <= stop:
        time = time + 1
        y.append(slope*(time-start))
    return y[1:numQRun]
    
    
def veganuary(x):
    veg = []
    tTime = 48
    while tTime <= 136:
        tTime = tTime + 4
        veg.append(runLognormal(tTime, x, 0.002885, 0.00577, 0.55)-runLognormal(tTime+1, x, 0.00173, 0.00376, 0.55))
    return sum(veg[1:22])
    
def veganuary2(x):
    veg2 = []
    tTime = 136
    while tTime <= 212:
        tTime = tTime + 4
        veg2.append(runLognormal(tTime, x, 0.0043275, 0.008655, 0.55)-runLognormal(tTime+1, x, 0.002592, 0.00519, 0.55))
    return sum(veg2[1:19])
    
        
def yFunction(totFunctions, initialPop, popGrowthFactor):
    x = 0
    Y = []
    y = initialPop * np.exp(popGrowthFactor * x/4)
    while x < 212:
        Y.append(y)
        y = initialPop - totFunctions*y
        x = x + 0.01
    return Y[1:21200]
        
        
    


     
x = np.linspace(0, 212, num=21200)
tax1 = runLognormal(92, x, 0.036, 0.071, 0.55)
tax2 = runLognormal(112, x, 0.036, 0.071, 0.55)
tax3 = runLognormal(132, x, 0.071, 0.142, 0.55)
tax4 = runLognormal(152, x, 0.036, 0.071, 0.55)
tax5 = runLognormal(200, x, 0.1065, 0.213, 0.55)
tariff = runLognormal(56, x, 0.018, 0.036, 0.55)
ad1 = runLognormal(4, x, 0.000575, 0.00115, 0.55)
ad2 = runLognormal(44, x, 0.00019, 0.00038, 0.55)
ad3 = runLognormal(84, x, 0.00019, 0.00038, 0.55)
ad4 = runLognormal(124, x, 0.000385, 0.00077, 0.55)
ad5 = runLognormal(144, x, 0.000575, 0.00115, 0.55)
ad6 = runLognormal(176, x, 0.00095, 0.0019, 0.55)
ad7 = runLognormal(200, x, 0.000575, 0.00115, 0.55)
news1 = runLognormal(1, x, 0.000345, 0.00069, 0.55)-runLognormal(2, x, 0.000207, 0.000414, 0.55)
veg = veganuary(x)
veg2 = veganuary2(x)
label1 = runLinear(80, 160, 0.0006875)
label2 = runLinear(160, 212, 0.003125)
#consumptionBase =
#popBase = 
#popOmniBase =
#popVegBase =
#popVeganBase =
veganGrowth = tax1 + tax2 + tax3 + tax4 + tax5 + tariff + ad1 + ad2 + ad3 + ad4 + ad5 + ad6 + ad7 + news1 + veg + veg2# + label1 + label2

ax.set_title('Decrease in Omnivore Population')
ax.set_xlabel('$Quarter$')
ax.set_ylabel('$Population Omnivores$')
ax.plot(x, yFunction(veganGrowth, initialPopOmni, popGrowthFactor), 'p-', lw=1, alpha=0.6, label='Major Graph')
Reply


Messages In This Thread
Memory error in python 2.7 - by Afterdarkreader - Dec-19-2017, 08:48 PM
RE: Memory error in python 2.7 - by Larz60+ - Dec-19-2017, 11:45 PM
RE: Memory error in python 2.7 - by Afterdarkreader - Dec-20-2017, 12:29 AM
RE: Memory error in python 2.7 - by Larz60+ - Dec-20-2017, 12:59 AM
RE: Memory error in python 2.7 - by Afterdarkreader - Dec-20-2017, 02:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Memory Error jason413 6 8,063 Jun-21-2018, 06:35 PM
Last Post: nilamo
  Memory error while recursively adding np.arrays Afterdarkreader 0 4,047 Dec-22-2017, 04:02 PM
Last Post: Afterdarkreader
  Memory Error rajeev1729 1 37,975 Sep-26-2017, 09:50 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020