Neural Mastery
← Practice
Inverted Dropout Layermedium

Inverted Dropout Layer

mediumDeep Learning⏱ 15 min
Libraries allowed · Pure Python earns +10 bonus XP
🎯 Mission
Implement Inverted Dropout where dropped elements are set to 0 and kept elements are scaled by 1 / (1 - p).

Task

Implement `dropout(x, drop_prob, mask)` returning scaled activation list.

Function Signature

dropout(x: list[float], drop_prob: float, mask: list[int]) -> list[float]

Examples

Example 1: Dropout p=0.5
Input: {"x":[2,4,6,8],"drop_prob":0.5,"mask":[1,0,1,0]}
Output: [4,0,12,0]

Constraints

  • Multiply kept values by 1 / (1 - drop_prob). Set dropped values to 0.0.
Python3Saved ✓
def dropout(x, drop_prob, mask):
"""
Applies inverted dropout using a binary mask (1 keep, 0 drop).
Inverted dropout scales kept values by 1 / (1 - drop_prob).
"""
# Your implementation here
pass

Case 1: Dropout p=0.5
Input: {"x":[2,4,6,8],"drop_prob":0.5,"mask":[1,0,1,0]}
Expected: [4,0,12,0]