python 3.x - Looping through lists, error : "float' object is not subscriptable". -
i want create new list of floats es. first value in es = first value in l1. rest of es based on below formula: need without using library/package.
formula: es1 = (a * l1t) + (1 - a) * es t-1
l1 = [430.92, 437.39, 535.03, 496.54, 520.72, 628.35, 679.06, 636.99, 574.81, 579.04, 598.50, 683.85] = 0.25 es = [] es.append(float(l1[0])) in range(1, len(l1)): es1 = (a * (l1[i])) + ((1 - a) * es[i-1]) es.append(float(es1[i])) print(es)
the error message tells all. if closely interpreter tells line in error occured. in line (es.append(float(es1[i]))
) try subscript value assigned float in previous line. can rid of float
constructors:
l1 = [430.92, 437.39, 535.03, 496.54, 520.72, 628.35, 679.06, 636.99, 574.81, 579.04, 598.50, 683.85] = 0.25 es = [] es.append(l1[0]) in range(1, len(l1)): es_i = (a * (l1[i])) + ((1 - a) * es[i-1]) es.append(es_i) print(es)
Comments
Post a Comment