Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-296

Mini Batch Gradient Mean

Problem

The mini-batch gradient is the elementwise mean of the per-sample gradients in the batch.

Given a list of gradient vectors, return their elementwise mean.

Hint

Average each coordinate across the batch.

Test cases

case 1
in: [[[1,2],[3,4]]]
expected: [2,3]
case 2
in: [[[1,0],[0,1],[2,2]]]
expected: [1,1]
case 3
in: [[[2,2],[4,4]]]
expected: [3,3]
Starter codePython
def mini_batch_gradient_mean(grads):
    # Your code here
    pass

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