TorchedUp
ProblemsPremium
TorchedUp
Batch NormalizationMedium
ProblemsPremium

Batch Normalization

Implement the batch normalization forward pass.

Signature: def batchnorm_forward(x: np.ndarray, gamma: np.ndarray, beta: np.ndarray, eps: float = 1e-5) -> np.ndarray

Normalize across the batch dimension (axis=0), then scale by gamma and shift by beta.

Example:

  • Input shape: (2, 3)
  • gamma: [1, 1, 1], beta: [0, 0, 0]

Math

Asked at

Python (numpy)0/3 runs today

Test Results

○identity scale/shift
○scaled output
○three rows🔒 Premium
○shift-invariant: bn(x) == bn(x + c) (mean subtracted)
○output is centered: column means ≈ 0 with identity gamma/beta
Advertisement