matplotlib - Unexpected Python TypeError: 'list' object is not callable -
i want draw 2 lines, each works when separated, when draw 2 @ time, there's error:
traceback (most recent call last): file "2.py", line 99, in fspe2 = [fspe(t2,x) t2 in t] typeerror: 'list' object not callable
full code:
# -*- coding: utf-8 -* import numpy np import matplotlib.pyplot plt import matplotlib mpl import math pylab import * c = 2.998*10**10 hp = 6.626*10**-27 hb = 1.055*10**-27 kb = 1.381*10**-16 g = 6.673*10**-8 me = 9.109*10**-28 mp = 1.673*10**-24 q = 4.803*10**-10 sigt = 6.652*10**-25 p = 2.5 r014 = 1 e53 = 1 g42 = 1 delt12 =1 epsbr2 = 1 epser1 = 1 dlg = 1 r0 = r014*10**14 e0 = e53*10**53 g4 = g42*10**2.5 delt0 = delt12*10**12 epser = epser1*0.1 epsbr = epsbr2*0.01 n1 = 1.0 k = 0 dl = dlg*3.086*10**27 n0 = e0/(g4*mp*c**2) sedl = (3*e0/(4*math.pi*n1*mp*c**2))**(1./3) ttw = delt0/c ttn = sedl/(2*c*g4**(3./8)) reta = sedl/g4**(2./3) def gam3(t): if delt0 > sedl/(2*g4**(8./3)): return np.where(t<ttw,(sedl/delt0)**(3./8)*(4*t/ttw)**(-1./4),(sedl/delt0)**(3./8)*(4*ttw/ttw)**(-1./4)*(t/ttw)**(-7./16)) else: return np.where(t<ttn,g4,g4*(t/ttn)**(-2./5)) def n3(t): if delt0 > sedl/(2*g4**(8./3)): return np.where(t<ttw,8*gam3(t)**3*n1/g4,8*gam3(ttw)**3*n1/g4*(t/ttw)**(-13./16)) else: return np.where(t<ttn,7*n1*g4**2*(t/ttn)**-3,7*n1*g4**2*(t/ttn)**(-6./7)) def e3(t): if delt0 > sedl/(2*g4**(8./3)): return np.where(t<ttw,4*gam3(t)**2*n1*mp*c**2,4*gam3(ttw)**2*n1*mp*c**2*(t/ttw)**(-13./12)) else: return np.where(t<ttn,4*g4**2*n1*mp*c**2,4*g4**2*n1*mp*c**2*(t/ttn)**(-8./7)) def ne3(t): if delt0 > sedl/(2*g4**(8./3)): return np.where(t<ttw,n0*(t/ttw),n0) else: return np.where(t<ttn,n0*(t/ttn)**(3./2),n0) gem = lambda t : epser*e3(t)/(n3(t)*me*c**2)*(p-2)/(p-1) br = lambda t : np.sqrt(8*math.pi*epsbr*e3(t)) gec = lambda t : 6*math.pi*me*c/(sigt*br(t)**2*gam3(t)*t) num = lambda t : 3*q*br(t)/(4*math.pi*me*c)*gem(t)**2*gam3(t) nuc = lambda t : 3*q*br(t)/(4*math.pi*me*c)*gec(t)**2*gam3(t) fmax = lambda t : ne3(t)*math.sqrt(3)*q**3*br(t)/(me*c**2)*gam3(t)/(4*math.pi*dl**2) def fspe(t,u): if num(t)<nuc(t): return np.where(u<num(t),(u/num(t))**(1./3)*fmax(t),np.where(u<nuc(t),(u/num(t))**(-(p-1.)/2)*fmax(t),(u/nuc(t))**(-p/2)*(nuc(t)/num(t))**(-(p-1.)/2)*fmax(t)))*u else: return np.where(u<nuc(t),(u/muc(t))**(1./3)*fmax(t),np.where(u<num(t),(u/nuc(t))**(-1./2)*fmax(t),(u/num(t))**(-p/2)*(num(t)/nuc(t))**(-1.2)*fmax(t)))*u xmin = 2 xmax = 10 = np.arange(xmin,xmax,0.01) t = 10**i plt.figure('god bless: lightcure') plt.title(r'lightcurve''\n2 cases') plt.xlabel(r'log t') plt.ylabel(r'log flux') x = 10**10 fspe = [fspe(t1,x) t1 in t] lightcurve1 = [math.log10(a5) a5 in fspe] plt.plot(i,lightcurve1,'.',label=r'$\nu=10^{10}$') ######################## ## strange thing happens!the above 4 sentences work well, ## why added same statements, there's error? x = 10**15 fspe2 = [fspe(t2,x) t2 in t] ### place feedback--traceback (most recent call last): # file "1.py", line 94, in <module> # fspe2 = [fspe(t2,x) t2 in t] #typeerror: 'list' object not callable lightcurve2 = [math.log10(a6) a6 in fspe2] plt.plot(i,lightcurve2,'>',label=r'$\nu=10^{15}$') ####################### plt.legend() plt.grid(true) plt.show()
traceback: literally, way trace path error message line caused it. python's error messages good, take says @ face value , follow back. it'll describe path of function calls produced result, serve breadcrumbs.
fspe2 = [fspe(t2,x) t2 in t] typeerror: 'list' object not callable
- where did call something? instance of in line
fspe(t2,x)
. - what did try call?
list
. therefore,fspe
list
@ point. - let's find out
fspe
assigned, searching term in editor or ide (or within browser window). def fspe(t,u):
- nope, defines function.fspe = [fspe(t1,x) t1 in t]
- there's our culprit! createdlist
involving previously-definedfspe
function, , assigned same namefspe
, masking function , making inaccessible (and, if there no more existing references it, removed entirely garbage collector).- the fix give unique name,
fspe3
orfspe_calcs
orfspe_list
.
Comments
Post a Comment