TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

6. Batch Normalization

Medium

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

x^=σ2+ϵ​x−μ​,y=γx^+β

Asked at

Python 30/10 runs today

Output

Anything you print() in your code will show up here after you click Run.

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