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
#5
They're the same code, but here's the error code for the abbreviated version I'm using to debug (it's the exact same code, just minus repeated functions that I know work fine).

First error
Error:
Traceback (most recent call last): File "<ipython-input-1-1ea6155a3286>", line 1, in <module> runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Linear function.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/Linear function.py", line 37, in <module> lbl1.plot(label1X, runLinear(80, 160, 0.0006875, label1X)) File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 1373, in plot for line in self._get_lines(*args, **kwargs): File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 304, in _grab_next_args for seg in self._plot_args(remaining, kwargs): File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 282, in _plot_args x, y = self._xy_from_xy(x, y) File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 223, in _xy_from_xy raise ValueError("x and y must have same first dimension") ValueError: x and y must have same first dimension
Second error (with the lbl1 print commented out
Error:
runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Linear function.py', wdir='C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction') Traceback (most recent call last): File "<ipython-input-2-1ea6155a3286>", line 1, in <module> runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Linear function.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/Linear function.py", line 40, in <module> veganGrowth = tax1 + label1 ValueError: operands could not be broadcast together with shapes (21200,) (0,)
Here's the code:
import numpy as np
from scipy.stats import lognorm
import matplotlib.pyplot as plt
from math import exp


def runLognormal(start, current, mean, cumImpact, peakFactor):
    scale = exp(mean)
    return lognorm.pdf(current, peakFactor, start, scale)*cumImpact
    
def runLinear(start, stop, changePerQ, x):
    y = np.array([])
    time = start
    while time <= stop:
        np.append(y, changePerQ)
        time = time + 0.01
    return y

     
x = np.linspace(0, 212, num=21200)
tax1 = runLognormal(92, x, 0.036, 0.071, 0.55)
label1 = runLinear(80, 160, 0.0006875, x)


############################################### GRAPH LABEL 1
fig, lbl1 = plt.subplots(1, 1)
label1X = np.linspace(80, 160, num = 8000)
lbl1.set_title('Text Based Labels')
lbl1.set_xlabel('Quarter')
lbl1.set_ylabel('Cumulative Effect')
lbl1.plot(label1X, runLinear(80, 160, 0.0006875, label1X))
##############################################################

veganGrowth = tax1 + label1

fig, ax = plt.subplots(1, 1)
ax.set_title('Instantaneous Rate of Change in Population')
ax.set_xlabel('$Quarter$')
ax.set_ylabel('$Population Omnivores$')
ax.plot(x, veganGrowth)
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 7,998 Jun-21-2018, 06:35 PM
Last Post: nilamo
  Memory error while recursively adding np.arrays Afterdarkreader 0 4,027 Dec-22-2017, 04:02 PM
Last Post: Afterdarkreader
  Memory Error rajeev1729 1 34,010 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