Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Image normalization is a simple but important preprocessing step in computer vision that makes pixel values comparable across images. In this problem, you’ll implement per-channel normalization for an RGB image represented as a NumPy array.
The normalization formula for each channel is:
Implement the function
Rules:
mean and std as length-3 arrays corresponding to [R, G, B].torchvision.transforms.Normalize).(H, W, 3).Output:
| Argument | Type |
|---|---|
| std | np.ndarray |
| mean | np.ndarray |
| image | np.ndarray |
| Return Name | Type |
|---|---|
| value | np.ndarray |
Use NumPy.
Keep output shape exactly (H, W, 3).
No prebuilt normalization utilities.
Use NumPy broadcasting: (H, W, 3) array minus (3,) array works automatically.
result = (image - mean) / std is all you need if shapes align correcty (last dim matches).
No loops are needed.