Nov-28-2019, 07:35 PM
I have a dot product calculating weighted means, and is applied to two columns in a list with the measured values in column 5 and 6:
This traverses the list of weights twice, which is inefficient and degrades performance. How could this be done in a more pythonic way?
I also have concerns about the main loop because of the correction with len(weights). Would this be considered more pythonic?:
# calculate weighted values in sequence for i in range(len(temperatures)-len(weights)): temperatures[i].append(sum([weights[j]*temperatures[i+j][5] for j in range(len(weights))])) temperatures[i].append(sum([weights[j]*temperatures[i+j][6] for j in range(len(weights))]))The calculation performs a running dot-product, appending both values to the list temperatures. The list of temperature samples is far larger than the list of weights, hence the correction of subtracting len(weights) at the end of the main loop.
This traverses the list of weights twice, which is inefficient and degrades performance. How could this be done in a more pythonic way?
I also have concerns about the main loop because of the correction with len(weights). Would this be considered more pythonic?:
# calculate weighted values in sequence for i in range(len(temperatures)): try: # insert weighted calculation here except: # do nothing, because array out of bounds