io - Python: Shifted Averaging And Space Delimiting -


i'm trying figure out average set of predictions (values between 0 , 1 model has created. prediction values shifted, however, such if there 10 data values predictions made in sets of 3 so:

0.6825 0.7022 0.7023 0.6193 0.6410 0.6389 0.5934 0.6159 0.6145 0.5966 0.6191 0.6184 0.3331 0.3549 0.3500 0.1862 0.2015 0.1999 0.1165 0.1270 0.1267 0.1625 0.1761 0.1740 

wherein these values correspond indexes follows:

1   2   3 2   3   4 3   4   5 4   5   6 5   6   7 6   7   8 7   8   9 8   9   10 

i'm trying write script such read input line line , output average of prediction values appropriate each index (average 2 twos together, 3 threes, 3 fours, etc) such there 1 per line:

0.6825 0.7001 etc... 

however, i'm not sure how read in data such i'm able differentiate between 0.6825 , 0.7022 in line 1, example. how read in information such i'm able store in contiguous array?

as far logic goes, figure can have special cases first, second, last, , second-to-last values, , run loop rest.

def linereader(fname):     open(fname) f:         line in f:             yield map(float, line.split())   result = [] data = [] i, line in enumerate(linereader('values.txt')):     data.append(line)     if == 0:         result.append(data[0][0])     elif == 1:         result.append((data[0][1] + data[1][0])/2)     else:         result.append((data[i-2][2] + data[i-1][1] + data[i][0])/3)  result.append((data[-2][2] + data[-2][1])/2) result.append(data[-1][2])  print result #[0.6825, 0.66075, 0.6455666666666667, 0.6171333333333333, 0.5222333333333333, 0.3865, 0.22266666666666668, 0.16313333333333332, 0.12685000000000002, 0.174] 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -