Rolling Mean and Standard Deviation
Xem dạng PDF
Gửi bài giải
Điểm:
100,00
Giới hạn thời gian:
2.0s
Giới hạn bộ nhớ:
256M
Tác giả:
Dạng bài
Ngôn ngữ cho phép
Python
Task
Given an array x of n floats and window size w, compute the rolling mean and rolling population standard deviation (ddof=0) for every full window. Output the rolling means on the first line and rolling stds on the second line.
Input
- Line 1: two ints
n w - Line 2:
nspace-separated floats
Output
Two lines, each with n - w + 1 space-separated floats (10 significant digits).
Example
Input:
6 3
1 3 5 4 2 6
Output:
3 4 3.666666667 4
1.632993162 0.8164965809 1.247219129 1.632993162
Scaffolding
def rolling_stats(x: list[float], w: int) -> tuple[list[float], list[float]]: ...
Notes
Track A: NumPy only. Use np.lib.stride_tricks.sliding_window_view or a loop. Population std divides by w, not w-1.
Bình luận