Premium problem165. Rolling Z-Score Over a Trailing Window

Medium Locked

Return a 1-D array of length len(x) - window + 1:

  • element i is (x[i+window-1] - mean(w)) / std(w) for the window w = x[i : i+window]
  • use population std
  • return 0.0 where the window's std is exactly zero

Input

x = [ 1.  2.  3.  4. 10.]
window = 3

Output

[1.22474487 1.22474487 1.40182605]

Premium problem

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

Implement solve(...)