0

I am getting TypeError: 'float' object has no attribute 'getitem' for my while statement below. I am not sure what the problem is in this case. I am using sys in the code

s1P = 4.51775*10.0**16.0
ii= 1 
while s1P[ii-1] > 0.0
    sys.stdout.write('\rstep={0}'.format(ii))
    sys.stdout.flush()

    Rad = s1r[ii-1]+delrms1[ii-1]*delm
    Mas = s1m[ii-1]*[i]
    Pres = s1P[ii-1]+delPms1[ii-1]*delm
    lPres = np.log10(Pres)
    Temp = s1T[ii-1]+delTms1[ii-1]*delm
    lTemp = np.log10(Temp)
    Lum = s1L[ii-1]+deLms1[ii-1]*delm

    Rho = (Pres - 1.0/3.0*a*Temp**4.0)*mu/(NA*k*Temp)
    lRho = np.log10(Rho)
    lR = np.log10(10.0**lRho/(10.0**Temp/10.0**6)**3.0)
    lK = interpolate.bisplev(lTemp,lR,tck)
    K = 10.0**lK
    T_n = Temp/(10.0**9.0)
    epp = 2.4*10.0**4.0*(Rho*X**2.0/T_n**(2.0/3.0))*np.exp(-3.38/T_n**(1.0/3.0))
    ecno = 4.4*10.0**25.0*(Rho*X*Z/T_n**(2.0/3.0))*np.exp(-15.228/T_n**(1.0/3.0))
    eta = 5.0*10.0**8.0*(Rho**2.0*Y**3.0/T_n**3.0)*np.exp(-4.4/T_n)
    ec = epp+ecno+eta
    Bt = NA*k*Rhoc*T_n/(Pres*mu)
    Gam2 =(32.0-24.0*Bt-3.0*Bt**2.0)/(24.0-18.0*Bt-3.0*Bt**2.0)
    drm =  1.0/(4.0*np.pi*Rad**2.0*Rho)
    dPm = -G*Mas*1.99*10.0**33.0/(4.0*np.pi*Rad**4.0)
    dLm = eg

    Term1 = 16.0*np.pi*a*c*G/(3.0*K)
    Term2 = (1.0-1.0/Gam2)
    Term3 = Temp**4.0*(Mas*1.99*10.0**33.0)/Pres
    Tal = Term1+Term2+Term3
    CR = Lum/Tal
    dTrm = -3.0*s1K*s1L/(64.0*np.pi**2.0*a*c*s1r**4.0*s1T**3.0)
    dTcm = -(1.0-1.0/s1gam2)*(G*s1m*1.99*10.0**33.0*s1T/(4.0*np.pi*s1r**4.0*s1P))
    dTm = np.where(Lum > Tal,  dTcm, dTrm)

    sys.stdout.write('\n')
    s1m.append(Mas)
    s1r.append(Rad)
    s1L.append(Lum)
    r_c.append(CR)
    s1T.append(Temp)
    logs1T.append(lTemp)
    s1P.append(Pres)
    logs1P.append(lPres)
    s1rho.append(Rho)
    logs1rho.append(lRho)
    logs1K.append(lK)
    slK.append(K)
    s1eg.append(ec)
    s1gam2.append(Gam2)
    delrms1.append(drm)
    delPms1.append(dPm)
    delLms1.append(dLm)
    delTm1.append(dTm)
    ii = ii+1

sys.stdout.write('\n')

s1m=s1m[:-1]
s1r=s1r[:-1]
s1L=s1L[:-1]
r_c=r_c[:-1]
s1T=s1T[:-1]
logs1T=logs1T[:-1]
s1P=s1P[:-1]
logs1P=logs1P[:-1]
s1rho=s1rho[:-1]
logs1rho=logs1K[:-1]
logs1K=logs1K[:-1]
slK=s1K[:-1]
s1eg=s1eg[:-1]
s1gam2=s1gam2[:-1]
delrms1=delrms1[:-1]
delPms1=delPms1[:-1]
delLms1=delLms1[:-1]
delTm1=delTm1[:-1]

Could still be a problem from appending the outputs of my statement?

5
  • 2
    Please show us where s1P is defined, and please include a complete stack trace. Commented Dec 10, 2013 at 16:37
  • 1
    What are you trying to accomplish with while s1P[ii-1] > 0.0? s1P is just a number, it doesn’t make sense to try to access an element (which is what [ii-1] does). Commented Dec 10, 2013 at 16:42
  • I edited what s1P is. Yes it is a number but this while statement should append new values for slP and stop if SlP > 0.0. At least, that is what I am aiming for. Commented Dec 10, 2013 at 16:47
  • Do you want s1P to be a single number or a list of numbers? It can’t be both at once. Commented Dec 10, 2013 at 16:48
  • It needs to be a list of numbers Commented Dec 10, 2013 at 16:50

1 Answer 1

2

If s1P is supposed to be a list of numbers then you need to initialize it like

s1P = [4.51775*10.0**16.0]

instead of s1P = 4.51775*10.0**16.0, which will make it a single number.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I forgot to initialized the value into a list. The error is gone now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.