mercredi 20 février 2019

IndexError: list index out of range in if

i am extremely new to Python. I have some code in R that I am trying to rewrite in Python and I've come across an issue that I can't seem to find an answer to - apologies if this has already been answered or the answer is obvious, I have searched and can't fix my issue.

I have a list 'height' which is a column of 481 numbers from a spreadsheet. I wish to use hrc, a list from the min to the max values of height, of the same length as the height list, but all values equally spaced. For each value in hrc i want to run it through the following code, but i get Indexerror: list index out of range.

hrc = np.linspace(min(height),max(height),len(height))
Qrc = []
for i in range(0,len(hrc)): 
  if(hrc[i]<0.685): 
      Qrc.append(30.69*((hrc[i]-0.156)**1.115))
  elif(0.685<=hrc[i] and hrc[i]<1.917):
      Qrc.append(27.884*((hrc[i]-0.028)**1.462))
  elif(1.917<=hrc[i]):
      Qrc.append(30.127*((hrc[i]-0.153)**1.502))

I appreciate any help!

Aucun commentaire:

Enregistrer un commentaire