All problems
Inverted Dropout (Seeded)
Problem
Inverted dropout in training mode: call random.seed(seed), then keep each element with probability 1 - p and scale survivors by 1 / (1 - p); dropped elements become 0.0.
The signature is inverted_dropout(x, p, seed). Iterate the elements in order so the output is reproducible.
Hint
Seed first, draw one random number per element, and scale kept values to preserve expectation.
Test cases
case 1
in: [[1,2,3,4,5],0.5,0]
expected: [2,4,0,0,10]
case 2
in: [[1,2,3],0,42]
expected: [1,2,3]
case 3
in: [[0.5,1.5,2.5],0.25,7]
expected: [0.6666666667,0,3.3333333333]
case 4
in: [[-1,2],0.8,123]
expected: [0,0]
Starter codePython
import random
def inverted_dropout(x, p, seed):
# Your code here
pass4 test cases · run your code against them in the editor