Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-254

Polyak Window Average

Problem

Average only the most recent parameter values.

Return the arithmetic mean of the last min(k, len(values)) entries. An empty list or a non-positive window returns 0.0.

Hint

Slicing from the end keeps the newest values and drops the oldest.

Test cases

case 1
in: [[1,2,3,4],2]
expected: 3.5
case 2
in: [[1,2],5]
expected: 1.5
case 3
in: [[],3]
expected: 0
case 4
in: [[5],0]
expected: 0
Starter codePython
def polyak_window_average(values, k):
    # Your code here
    pass

4 test cases · run your code against them in the editor