0
Rgas = 8.314e7   # erg/K/mol
Av = 6.022e23  # avagadro's number
mp= 1.67e-24  # hydrogen molec

# Name, ty, dist, M, R, Period, Temp, mu (H2=2, He = 4), cp
data  = []

data.append(["HD 209458 b", "hot-J",0.047*AU, 0.68*MJ, 1.36*RJ, 3.525*day, 0, 0,0])
data.append(["Positiveuncertainty", "uncertainty",0.00045*AU, 0.014*MJ, 0.016*RJ, 0, 0, 0,0])
data.append(["Negativeuncertainty", "uncertainty",0.00047*AU, 0.015*MJ, 0.019*RJ, 0, 1450, 2.3,1.59e4*cp2cgs])
data.append(["Kepler-7b", "hot-J",0.063*AU, 0.45*MJ,1.57*RJ, 4.89*day, 1630, 2.3,1.63e4*cp2cgs])
data.append(["Positiveuncertainty", "uncertainty",0.0012*AU, 0.051*MJ,0.0749*RJ, 0, 10, 0,0])
data.append(["Negativeuncertainty", "uncertainty",0.0013*AU, 0.048*MJ,0.0708*RJ, 0, 10, 0,0])

for d in data:
    nm,ty,asemi,M,a,P,T,mu,cp = d
    Om = 2*np.pi/P
    g = G*M/a**2 # surface accel
    Rspec = Rgas/(Av*mu*mp)  #/(mu*mp)

    #cp = 7/2*(Rgas/(Av*28.97*mp)); print(cp/1e4); quit()
    H = Rspec*T/g
    if ty == 'uncertainty':
        H = 

The code is not full, it is just including the part I have a problem with.

I want to put uncertainty values separated from the data row.

However, since the H formula includes division, I would need to define the relative uncertainty, which should be the absolute uncertainty over the data value itself. Thus, to get relative uncertainty, I have to obtain the data value from the upper row. How can I do this?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Brian Jan
  • 29
  • 3
  • 1
    You should try and post a *minimal, reproducible example*. Also, `data[-1]` will give you the last element if that helps. – niko Jan 19 '22 at 11:41
  • Evidently, your question is not about *creating* the list (with `.append`), but with *using* it. You want your `for` loop to assign two values each time around - representing two adjacent elements of the list - rather than just one. To do this, you need what is commonly called a sliding (or rolling) window iterator. Please see the linked duplicate for details. – Karl Knechtel Jan 19 '22 at 11:42
  • 1
    I suggest that you rephrase you question so that it includes only the actual problem, and only what's relevant to that problem. For example, it seems that your problem here relates to constructing an array of values. So all that TMI about "uncertainty" (and in fact, all of these numeric values up there) seems completely irrelevant here, and it only adds confusion for anyone trying to read and answer your question. –  Jan 19 '22 at 11:43
  • You should also read [ask] and https://stackoverflow.com/help/minimal-reproducible-example. Be willing to take the code out of context, and work with the smallest data that causes the same fundamental *problem*. – Karl Knechtel Jan 19 '22 at 11:45
  • Be nice to the astronomer who is new here :) @Brian Jan one problem is that you aren't explicitly tracking which uncertainties belong to which object's measurement. So you can iterate through but it's slightly dangerous assumption. Let me attempt an answer. – jtlz2 Jan 19 '22 at 11:47
  • I agree with all the comments above. I'm not sure that the reason for closing your question is correct, but if I understood your real question, you can access the former item of a by getting indexes of the list items like this: `for i, d in enumerate(data):` and then access the item like this: `data[i-1]`. note that for `i=0` you'll access the last element of the list. – Daniel Jan 19 '22 at 11:47
  • I think that duplicated answer could help here. @BrianJab consider a different data structure to a list of lists e.g. dict keyed by object name. Or numpy. Or even pandas... For everyone else, the tone of the above comments might sound terrible in aggregate. It only looks like too much information to the non-domain expert. Plenty of people write their examples in domain-specific language. Meet the (brand new) OP where they are at, and try not to give them "TMI" in return. I'm sure the review queue instructions say to be nice to new people, do they not? – jtlz2 Jan 19 '22 at 11:54
  • Thank you for your answers. Among the suggestions you have made, I chose to include the uncertainty values inside the datas themselves. This caused another problem... but I am working on it. – Brian Jan Jan 26 '22 at 10:37

0 Answers0