Part of a program I'm writing has code that calculates the following:
data = np.array(..........)
param = np.array(range(100)+1)
result = np.array([data[-x:].mean() for x in param])
This code is used in a giant loop so performance is crucial. It shows that the 3rd line (result = ...) takes the most time of all - I wonder if there are better ways to do this operation?
Any suggestions are appreciated!
np.array(range(100)+1)this isn't valid? Do you meannp.arange(100)+1? Also, are you really collecting the averages of the array backwards (last sample, last 2 samples, last 3 samples, etc.)data-sciencetag as it's not relevant here.