Python array indexing within for loop -
this programme aims generate resistance value according to:
(given array of resistances , temperatures).
in order obtain current value of resistance, equation requires initial resistance , initial temperature values (r_0, t_0) array. requires successive value of temperature (t) array.
my try:
r_model=[] r in r_values: result = r*(1+2.9*(t_values[r+1]-t_values[r])) fit2.append(result) r_model = array(r_model) my error:
index out of bounds
if need array index while processing for loop, can utilize enumerate:
r_model=[] (index, r) in enumerate(r_values): result = r*(1+2.9*(t_values[index+1]-t_values[index])) fit2.append(result) r_model = array(r_model) if r_values [1500,2500,0.0001], enumerate(r_values) iterate through sequence:
(0, 1500) (1,2500) (2,0.0001) and @ each step, can utilize index (0,1, , 2) proper value t_values list.
python for-loop indexing
No comments:
Post a Comment