I am working on a data processing project in which I would generally like to take a 1D numpy array as input, and output an equal length array who's elements were generated by processing a certain number of input elements. This is a relatively simple problem to solve using a for loop, but I am wondering if numpy has a built in way of doing this, which I assume would be significantly faster.
To illustrate my goals, imagine generating a vector (B) 1 element at a time, and let the current element being generated be element N (denoted B[N]).
Say I want B to be a vector whose elements correspond to a simple moving average of the elements in vector A. What I want to be able to say is
B[i] = AVG(A[(i-N):i]) #N <= i < len(A)
Where i here is the iteration index of whatever underlying loop is running and AVG is a generic function which calculates the average of the group of numbers passed to it.
As I said, easy enough with a for loop, but this seems like a thing something like numpy should be able to do quite easily so I thought I'd ask the pros before I litter my code with less than optimal structures.