Hi I am trying to create a new array from a previous array. such that in new array the first element is mean of first 20 elements from existing array. Here is my code. I am not sure why its not working.
#Averages RPMA=[] for i in range(9580): for j in range (0,191600): a=RPM.iloc[j:j+20] RPMA(i)= a.mean()
Looks to me like you're using the wrong kind of brackets. This line:
RPMA(i)= a.mean()
...should probably be this:
RPMA[i]= a.mean()
But I'm no Python expert. I guessing that it thinks RPMA(i)
is a function because you use parentheses, in which case you would be trying to assign a value to a function call, like the error says.
However trying to assign a new value past the end of the array will result in an IndexError
because the array element doesn't exist, and will need to be added. What you can do instead is this:
RPMA.append(a.mean())
...which will append the data to the end of the array (i.e. adding a new element).
Thanks everyone. As suggested by most of you, I made below changes in code and now its working just fine!
RPMA=[] for j in range (0,191600, 20): a=RPM.iloc[j:j+19] RPMA.append(a.mean())