I have a question about how to get the average of every 2 elements in a list in python. Ex:
a = [1, 3, 4, 1, 5, 2]
In this case, as it needs to compute (1 + 4 + 5)/3 and the next one (3 + 1 + 2)/3. The new list would have the following values:
amean = [3.3333,2]
So far I have managed to average, but I have no idea how to create a loop for it to return and start the average on the second element (3 + 1 + 2)/3.
Here's a piece of what I have done so far:
import numpy as np
a = [1.,3.,4.,1., 5., 2.]
def altElement(my_list):
b = my_list[:len(my_list):2]
print b
return np.mean(b)
print altElement(a)
Does anyone have any idea how to create this loop? Here's a link for the code that I have done so far: code