Batch Normalization Forward

Medium
~15 min
code completion

Batch Normalization

Batch normalization normalizes each feature across the batch dimension, stabilizing training and allowing higher learning rates.

For a mini-batch of activations of shape (m, d):

Each column (feature) is independently normalized to zero mean and unit variance. The prevents division by zero.

Note: In the full layer, is then scaled and shifted by learned parameters and — we skip that here.

Your task:

Implement batch_normalize(X, eps) that normalizes each feature column.

Example Tests

Sum of normalized output is 0 (all columns are zero-mean)

Input: {"X":[[1,10],[2,20],[3,30]],"eps":0}

Expected: 0

Each column has unit std (check element value)

Input: {"X":[[1,2],[3,4],[5,6]],"eps":0}

Expected: [[-1.22474,-1.22474],[0,0],[1.22474,1.22474]]

Output shape preserved

Input: {"X":[[1,2,3],[4,5,6]],"eps":1e-8}

Expected: [2,3]

Sign in to solve this problem

You can read the full problem statement above. Create a free account to run code in the browser, submit solutions, and track your progress.