A weighted moving average smooths a sequence while allowing different positions within each window to have different influence. For values x, weights w, and window length k = len(weights), compute
WMAi=∑j=0k−1wj∑j=0k−1wjxi+jHere, i is the window's starting index, x_{i+j} is a value in that window, and w_j is the corresponding weight. Evaluate every window that fits completely inside values. Return the weighted averages as a list of floats.
Input: values = [1, 2, 3, 4, 5], weights = [1, 1, 1]
Output: [2.0, 3.0, 4.0]
Explanation: Equal weights make each result the ordinary mean of its three-value window.
Input: values = [10, 20, 30, 40], weights = [1, 2, 3]
Output: [23.333333, 33.333333]
Compute sum(weights) once before processing the windows.
For a window beginning at i, pair weights[j] with values[i + j].
Sign in to take notes on this problem
Accepts: array
Accepts: array
A weighted moving average smooths a sequence while allowing different positions within each window to have different influence. For values x, weights w, and window length k = len(weights), compute
WMAi=∑j=0k−1wj∑j=0k−1wjxi+jHere, i is the window's starting index, x_{i+j} is a value in that window, and w_j is the corresponding weight. Evaluate every window that fits completely inside values. Return the weighted averages as a list of floats.
Input: values = [1, 2, 3, 4, 5], weights = [1, 1, 1]
Output: [2.0, 3.0, 4.0]
Explanation: Equal weights make each result the ordinary mean of its three-value window.
Input: values = [10, 20, 30, 40], weights = [1, 2, 3]
Output: [23.333333, 33.333333]
Compute sum(weights) once before processing the windows.
For a window beginning at i, pair weights[j] with values[i + j].
Sign in to take notes on this problem
Accepts: array
Accepts: array