Layer Normalization
~12 mincode completion
Implement layer_normalize(x, eps) for a single 1D input vector.
Examples
Known normalized values
- Input
- layer_normalize([1, 3, 5], 0)
- Output
- [-1.22474, 0, 1.22474]
Constant input: zero after normalization (with eps)
- Input
- layer_normalize([7, 7, 7], 1)
- Output
- [0, 0, 0]
Hints
Hint 1
Work directly with the arguments x, eps and return the result rather than printing it.
Hint 2
Watch for this: normalized column wise not element wise.
Requirements
x: 1D input vector of shape (d,)eps: Numerical stability constantReturn Normalized vector of shape (d,) with mean ≈ 0, std ≈ 1.
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Try similar problems(1)
Where this shows up
~12 min
••••••••••••••••
8 employers weight this skill
4 frontier labs, 2 big tech firms, 1 autonomy company, 1 enterprise vendor. Top match scores 81.
Python
import numpy as np
def layer_normalize(x: np.ndarray, eps: float = 1e-8) -> np.ndarray:
"""
Apply layer normalization to a 1D vector.
Args:
x: 1D input vector of shape (d,)
eps: Numerical stability constant
Returns:
Normalized vector of shape (d,) with mean ≈ 0, std ≈ 1.
"""
# YOUR CODE HERE
pass