Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Implement the forward pass of Batch Normalization for a mini-batch, a core building block in deep learning that stabilizes activations during training. You’ll compute per-feature mean/variance over the batch, normalize, then apply learnable scale and shift.
Implement the function
Rules:
m*d).Output:
| Argument | Type |
|---|---|
| X | np.ndarray |
| eps | float |
| beta | np.ndarray |
| gamma | np.ndarray |
| Return Name | Type |
|---|---|
| value | np.ndarray |
Use NumPy vectorization; no elementwise Python loops
Variance uses 1/m (no Bessel correction)
Return NumPy array
Use axis=0 to compute mean and variance per feature.
Variance must be no Bessel correction: var = np.mean((x - mu)**2, axis=0); then normalize with np.sqrt(var + eps).
Use broadcasting for the affine step: y = gamma * x_hat + beta.