Premium problem29. Moving Average Over a Window

Hard Locked

Compute the moving average of vector Z over a sliding window of size n. Return a vector of length len(Z) - n + 1, where element i is the mean of Z[i:i+n].

Input

Z = tensor([ 0,  1,  2,  ..., 17, 18, 19])
n = 3

Output

tensor([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10., 11., 12., 13., 14.,
        15., 16., 17., 18.])

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)