Premium problem29. Sliding Window Average

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.,  ..., 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(...)